diff --git a/README.md b/README.md index 6ec00101..b84284b9 100644 --- a/README.md +++ b/README.md @@ -62,7 +62,6 @@ - \ - Table of contents - Local search, use [flexsearch](https://github.com/nextapps-de/flexsearch) -- Twitter page template - GitHub page template - Archive page template - [GitHub Actions](https://github.com/features/actions) diff --git a/README.zh.md b/README.zh.md index b599ea5c..9e5bb9f4 100644 --- a/README.zh.md +++ b/README.zh.md @@ -61,7 +61,6 @@ - 图片懒加载 - noscript 支持 - 本地搜索支持,使用 [flexsearch](https://github.com/nextapps-de/flexsearch) -- Twitter 页面 - GitHub 页面 - 归档页面 - [GitHub Actions](https://github.com/features/actions) 支持 @@ -180,7 +179,7 @@ Luna 主题支持大量的 Shortcodes,请查看:[Shortcodes](https://hugo-th ## 📝 注意 -如果你所在的国家或地区无法访问 Twitter 或 GitHub,请不要使用这两个模板文件,否则会出现错误。 +如果你所在的国家或地区无法访问 GitHub,请不要使用这个模板文件,否则会出现错误。 博客内图片均使用了 Hugo 的 [Image Processing](https://gohugo.io/content-management/image-processing/) 功能,自动裁剪成合适的大小来优化页面加载速度,首次生成可能较为耗费时间。 diff --git a/assets/jsconfig.json b/assets/jsconfig.json index 377218cc..e2f84925 100644 --- a/assets/jsconfig.json +++ b/assets/jsconfig.json @@ -1,10 +1,10 @@ { - "compilerOptions": { - "baseUrl": ".", - "paths": { - "*": [ - "*" - ] - } - } -} \ No newline at end of file + "compilerOptions": { + "baseUrl": ".", + "paths": { + "*": ["*", "./ts/modules/*", "node_modules/*"], + }, + "lib": ["es2020", "dom"], + }, + "include": ["./ts/modules/*", "./ts/window.d.ts"], +} diff --git a/assets/sass/_common/_google_translator.scss b/assets/sass/_common/_google_translator.scss index 4c35d613..1c4690ee 100644 --- a/assets/sass/_common/_google_translator.scss +++ b/assets/sass/_common/_google_translator.scss @@ -20,4 +20,7 @@ .skiptranslate { margin-bottom: 0px; } + span[style="white-space:nowrap"] { + display: none; + } } diff --git a/assets/sass/modules/katex.css b/assets/sass/modules/katex.css index e532aec7..375c79a1 100644 --- a/assets/sass/modules/katex.css +++ b/assets/sass/modules/katex.css @@ -127,10 +127,12 @@ } .katex * { -ms-high-contrast-adjust: none !important; +} +.katex * { border-color: currentColor; } .katex .katex-version::after { - content: "0.16.4"; + content: "0.16.8"; } .katex .katex-mathml { /* Accessibility hack to only show to screen readers diff --git a/assets/translate-google.js b/assets/translate-google.js index c68cbb82..0529fff6 100644 --- a/assets/translate-google.js +++ b/assets/translate-google.js @@ -1,166 +1,16 @@ (function () { - var gtConstEvalStartTime = new Date(); - var h = this || self, - l = /^[\w+/_-]+[=]{0,2}$/, - m = null; - function n(a) { - return (a = a.querySelector && a.querySelector("script[nonce]")) && (a = a.nonce || a.getAttribute("nonce")) && - l.test(a) ? a : "" - } - function p(a, b) { - function c() {} - c.prototype = b.prototype; - a.i = b.prototype; - a.prototype = new c; - a.prototype.constructor = a; - a.h = function (g, f, k) { - for (var e = Array(arguments.length - 2), d = 2; d < arguments.length; d++) e[d - 2] = arguments[d]; - return b.prototype[f].apply(g, e) - } - } - function q(a) { - return a - }; - function r(a) { - if (Error.captureStackTrace) Error.captureStackTrace(this, r); - else { - var b = Error().stack; - b && (this.stack = b) - } - a && (this.message = String(a)) - } - p(r, Error); - r.prototype.name = "CustomError"; - function u(a, b) { - a = a.split("%s"); - for (var c = "", g = a.length - 1, f = 0; f < g; f++) c += a[f] + (f < b.length ? b[f] : "%s"); - r.call(this, c + a[g]) - } - p(u, r); - u.prototype.name = "AssertionError"; - function v(a, b) { - throw new u("Failure" + (a ? ": " + a : ""), Array.prototype.slice.call(arguments, 1)); - }; - var w; - function x(a, b) { - this.g = b === y ? a : "" - } - x.prototype.toString = function () { - return this.g + "" - }; - var y = {}; - function z(a) { - var b = document.getElementsByTagName("head")[0]; - b || (b = document.body.parentNode.appendChild(document.createElement("head"))); - b.appendChild(a) - } - function _loadJs(a) { - var b = document; - var c = "SCRIPT"; - "application/xhtml+xml" === b.contentType && (c = c.toLowerCase()); - c = b.createElement(c); - c.type = "text/javascript"; - c.charset = "UTF-8"; - if (void 0 === w) { - b = null; - var g = h.trustedTypes; - if (g && g.createPolicy) { - try { - b = g.createPolicy("goog#html", { - createHTML: q, - createScript: q, - createScriptURL: q - }) - } catch (t) { - h.console && h.console.error(t.message) - } - w = b - } else w = b - } - a = (b = w) ? b.createScriptURL(a) : a; - a = new x(a, y); - a: { - try { - var f = c && c.ownerDocument, - k = f && (f.defaultView || f.parentWindow); - k = k || h; - if (k.Element && k.Location) { - var e = k; - break a - } - } catch (t) {} - e = null - } - if (e && "undefined" != typeof e.HTMLScriptElement && (!c || !(c instanceof e.HTMLScriptElement) && (c instanceof e - .Location || c instanceof e.Element))) { - e = typeof c; - if ("object" == e && null != c || "function" == e) try { - var d = c.constructor.displayName || c.constructor.name || Object.prototype.toString.call(c) - } catch (t) { - d = "" - } else d = void 0 === c ? "undefined" : null === c ? "null" : typeof c; - v("Argument is not a %s (or a non-Element, non-Location mock); got: %s", - "HTMLScriptElement", d) - } - a instanceof x && a.constructor === x ? d = a.g : (d = typeof a, v( - "expected object of type TrustedResourceUrl, got '" + a + "' of type " + ("object" != d ? d : a ? - Array.isArray(a) ? "array" : d : "null")), d = "type_error:TrustedResourceUrl"); - c.src = d; - (d = c.ownerDocument && c.ownerDocument.defaultView) && d != h ? d = n(d.document) : (null === m && (m = n( - h.document)), d = m); - d && c.setAttribute("nonce", d); - z(c) - } - function _loadCss(a) { - var b = document.createElement("link"); - b.type = "text/css"; - b.rel = "stylesheet"; - b.charset = "UTF-8"; - b.href = a; - z(b) - } - function _isNS(a) { - a = a.split("."); - for (var b = window, c = 0; c < a.length; ++c) - if (!(b = b[a[c]])) return !1; - return !0 - } - function _setupNS(a) { - a = a.split("."); - for (var b = window, c = 0; c < a.length; ++c) b.hasOwnProperty ? b.hasOwnProperty(a[c]) ? b = b[a[c]] : b = - b[a[c]] = {} : b = b[a[c]] || (b[a[c]] = {}); - return b - } - window.addEventListener && "undefined" == typeof document.readyState && window.addEventListener( - "DOMContentLoaded", - function () { - document.readyState = "complete" - }, !1); - if (_isNS('google.translate.Element')) { - return - }(function () { - var c = _setupNS('google.translate._const'); - c._cest = gtConstEvalStartTime; - gtConstEvalStartTime = undefined; - c._cl = navigator.language || navigator.userLanguage; - c._cuc = 'googleTranslateElementInit'; - c._cac = ''; - c._cam = ''; - c._ctkk = '449649.3822363247'; - var h = 'translate.googleapis.com'; - var s = (true ? 'https' : window.location.protocol == 'https:' ? 'https' : 'http') + '://'; - var b = s + h; - c._pah = h; - c._pas = s; - // c._pbi = b + '/translate_static/img/te_bk.gif'; - c._pbi = ''; - c._pci = b + '/translate_static/img/te_ctrl3.gif'; - c._pli = b + '/translate_static/img/loading.gif'; - c._plla = h + '/translate_a/l'; - c._pmi = b + '/translate_static/img/mini_google.png'; - c._ps = window.translateelement_styles; - c._puh = 'translate.google.cn'; - _loadCss(c._ps); - _loadJs(b + `/translate_static/js/element/main.js`); - })(); + window.googleTranslateElementInit = function () { + new google.translate.TranslateElement( + {pageLanguage: 'en'}, + 'google_translate_element' + ); + } + + var addScript = function (url) { + var script = document.createElement('script'); + script.src = url; + document.body.appendChild(script); + } + + addScript('//translate.google.com/translate_a/element.js?cb=googleTranslateElementInit'); })(); \ No newline at end of file diff --git a/assets/ts/main.ts b/assets/ts/main.ts index ca8e369f..fe04baaa 100644 --- a/assets/ts/main.ts +++ b/assets/ts/main.ts @@ -1,5 +1,5 @@ // import * as params from '@params'; - +import './window.d.ts'; import initConsoleStyle from './src/initConsoleStyle'; import initHugoEncrypt from './src/initHugoEncrypt'; import initPjax from './src/initPjax'; diff --git a/assets/ts/modules/katex.js b/assets/ts/modules/katex.js index c6d946eb..8abf72d2 100644 --- a/assets/ts/modules/katex.js +++ b/assets/ts/modules/katex.js @@ -50,13 +50,19 @@ __webpack_require__.d(__webpack_exports__, { * If possible, a caller should provide a Token or ParseNode with information * about where in the source string the problem occurred. */ -var ParseError = // Error position based on passed-in Token or ParseNode. +var ParseError = // Error start position based on passed-in Token or ParseNode. +// Length of affected text based on passed-in Token or ParseNode. +// The underlying error message without any context added. function ParseError(message, // The error message token // An object providing position information ) { + this.name = void 0; this.position = void 0; + this.length = void 0; + this.rawMessage = void 0; var error = "KaTeX parse error: " + message; var start; + var end; var loc = token && token.loc; if (loc && loc.start <= loc.end) { @@ -65,7 +71,7 @@ token // An object providing position information var input = loc.lexer.input; // Prepend some information start = loc.start; - var end = loc.end; + end = loc.end; if (start === input.length) { error += " at end of input: "; @@ -95,14 +101,20 @@ token // An object providing position information error += left + underlined + right; } // Some hackery to make ParseError a prototype of Error // See http://stackoverflow.com/a/8460753 + // $FlowFixMe var self = new Error(error); self.name = "ParseError"; // $FlowFixMe - self.__proto__ = ParseError.prototype; // $FlowFixMe - + self.__proto__ = ParseError.prototype; self.position = start; + + if (start != null && end != null) { + self.length = end - start; + } + + self.rawMessage = message; return self; }; // $FlowFixMe More hackery @@ -728,49 +740,49 @@ function supportedCodepoint(codepoint) { * It's a storehouse of path geometry for SVG images. */ // In all paths below, the viewBox-to-em scale is 1000:1. -var hLinePad = 80; // padding above a sqrt viniculum. Prevents image cropping. -// The viniculum of a \sqrt can be made thicker by a KaTeX rendering option. -// Think of variable extraViniculum as two detours in the SVG path. -// The detour begins at the lower left of the area labeled extraViniculum below. -// The detour proceeds one extraViniculum distance up and slightly to the right, -// displacing the radiused corner between surd and viniculum. The radius is +var hLinePad = 80; // padding above a sqrt vinculum. Prevents image cropping. +// The vinculum of a \sqrt can be made thicker by a KaTeX rendering option. +// Think of variable extraVinculum as two detours in the SVG path. +// The detour begins at the lower left of the area labeled extraVinculum below. +// The detour proceeds one extraVinculum distance up and slightly to the right, +// displacing the radiused corner between surd and vinculum. The radius is // traversed as usual, then the detour resumes. It goes right, to the end of -// the very long viniculumn, then down one extraViniculum distance, +// the very long vinculum, then down one extraVinculum distance, // after which it resumes regular path geometry for the radical. -/* viniculum +/* vinculum / - /▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒←extraViniculum - / █████████████████████←0.04em (40 unit) std viniculum thickness + /▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒←extraVinculum + / █████████████████████←0.04em (40 unit) std vinculum thickness / / / / / /\ / / surd */ -var sqrtMain = function sqrtMain(extraViniculum, hLinePad) { +var sqrtMain = function sqrtMain(extraVinculum, hLinePad) { // sqrtMain path geometry is from glyph U221A in the font KaTeX Main - return "M95," + (622 + extraViniculum + hLinePad) + "\nc-2.7,0,-7.17,-2.7,-13.5,-8c-5.8,-5.3,-9.5,-10,-9.5,-14\nc0,-2,0.3,-3.3,1,-4c1.3,-2.7,23.83,-20.7,67.5,-54\nc44.2,-33.3,65.8,-50.3,66.5,-51c1.3,-1.3,3,-2,5,-2c4.7,0,8.7,3.3,12,10\ns173,378,173,378c0.7,0,35.3,-71,104,-213c68.7,-142,137.5,-285,206.5,-429\nc69,-144,104.5,-217.7,106.5,-221\nl" + extraViniculum / 2.075 + " -" + extraViniculum + "\nc5.3,-9.3,12,-14,20,-14\nH400000v" + (40 + extraViniculum) + "H845.2724\ns-225.272,467,-225.272,467s-235,486,-235,486c-2.7,4.7,-9,7,-19,7\nc-6,0,-10,-1,-12,-3s-194,-422,-194,-422s-65,47,-65,47z\nM" + (834 + extraViniculum) + " " + hLinePad + "h400000v" + (40 + extraViniculum) + "h-400000z"; + return "M95," + (622 + extraVinculum + hLinePad) + "\nc-2.7,0,-7.17,-2.7,-13.5,-8c-5.8,-5.3,-9.5,-10,-9.5,-14\nc0,-2,0.3,-3.3,1,-4c1.3,-2.7,23.83,-20.7,67.5,-54\nc44.2,-33.3,65.8,-50.3,66.5,-51c1.3,-1.3,3,-2,5,-2c4.7,0,8.7,3.3,12,10\ns173,378,173,378c0.7,0,35.3,-71,104,-213c68.7,-142,137.5,-285,206.5,-429\nc69,-144,104.5,-217.7,106.5,-221\nl" + extraVinculum / 2.075 + " -" + extraVinculum + "\nc5.3,-9.3,12,-14,20,-14\nH400000v" + (40 + extraVinculum) + "H845.2724\ns-225.272,467,-225.272,467s-235,486,-235,486c-2.7,4.7,-9,7,-19,7\nc-6,0,-10,-1,-12,-3s-194,-422,-194,-422s-65,47,-65,47z\nM" + (834 + extraVinculum) + " " + hLinePad + "h400000v" + (40 + extraVinculum) + "h-400000z"; }; -var sqrtSize1 = function sqrtSize1(extraViniculum, hLinePad) { +var sqrtSize1 = function sqrtSize1(extraVinculum, hLinePad) { // size1 is from glyph U221A in the font KaTeX_Size1-Regular - return "M263," + (601 + extraViniculum + hLinePad) + "c0.7,0,18,39.7,52,119\nc34,79.3,68.167,158.7,102.5,238c34.3,79.3,51.8,119.3,52.5,120\nc340,-704.7,510.7,-1060.3,512,-1067\nl" + extraViniculum / 2.084 + " -" + extraViniculum + "\nc4.7,-7.3,11,-11,19,-11\nH40000v" + (40 + extraViniculum) + "H1012.3\ns-271.3,567,-271.3,567c-38.7,80.7,-84,175,-136,283c-52,108,-89.167,185.3,-111.5,232\nc-22.3,46.7,-33.8,70.3,-34.5,71c-4.7,4.7,-12.3,7,-23,7s-12,-1,-12,-1\ns-109,-253,-109,-253c-72.7,-168,-109.3,-252,-110,-252c-10.7,8,-22,16.7,-34,26\nc-22,17.3,-33.3,26,-34,26s-26,-26,-26,-26s76,-59,76,-59s76,-60,76,-60z\nM" + (1001 + extraViniculum) + " " + hLinePad + "h400000v" + (40 + extraViniculum) + "h-400000z"; + return "M263," + (601 + extraVinculum + hLinePad) + "c0.7,0,18,39.7,52,119\nc34,79.3,68.167,158.7,102.5,238c34.3,79.3,51.8,119.3,52.5,120\nc340,-704.7,510.7,-1060.3,512,-1067\nl" + extraVinculum / 2.084 + " -" + extraVinculum + "\nc4.7,-7.3,11,-11,19,-11\nH40000v" + (40 + extraVinculum) + "H1012.3\ns-271.3,567,-271.3,567c-38.7,80.7,-84,175,-136,283c-52,108,-89.167,185.3,-111.5,232\nc-22.3,46.7,-33.8,70.3,-34.5,71c-4.7,4.7,-12.3,7,-23,7s-12,-1,-12,-1\ns-109,-253,-109,-253c-72.7,-168,-109.3,-252,-110,-252c-10.7,8,-22,16.7,-34,26\nc-22,17.3,-33.3,26,-34,26s-26,-26,-26,-26s76,-59,76,-59s76,-60,76,-60z\nM" + (1001 + extraVinculum) + " " + hLinePad + "h400000v" + (40 + extraVinculum) + "h-400000z"; }; -var sqrtSize2 = function sqrtSize2(extraViniculum, hLinePad) { +var sqrtSize2 = function sqrtSize2(extraVinculum, hLinePad) { // size2 is from glyph U221A in the font KaTeX_Size2-Regular - return "M983 " + (10 + extraViniculum + hLinePad) + "\nl" + extraViniculum / 3.13 + " -" + extraViniculum + "\nc4,-6.7,10,-10,18,-10 H400000v" + (40 + extraViniculum) + "\nH1013.1s-83.4,268,-264.1,840c-180.7,572,-277,876.3,-289,913c-4.7,4.7,-12.7,7,-24,7\ns-12,0,-12,0c-1.3,-3.3,-3.7,-11.7,-7,-25c-35.3,-125.3,-106.7,-373.3,-214,-744\nc-10,12,-21,25,-33,39s-32,39,-32,39c-6,-5.3,-15,-14,-27,-26s25,-30,25,-30\nc26.7,-32.7,52,-63,76,-91s52,-60,52,-60s208,722,208,722\nc56,-175.3,126.3,-397.3,211,-666c84.7,-268.7,153.8,-488.2,207.5,-658.5\nc53.7,-170.3,84.5,-266.8,92.5,-289.5z\nM" + (1001 + extraViniculum) + " " + hLinePad + "h400000v" + (40 + extraViniculum) + "h-400000z"; + return "M983 " + (10 + extraVinculum + hLinePad) + "\nl" + extraVinculum / 3.13 + " -" + extraVinculum + "\nc4,-6.7,10,-10,18,-10 H400000v" + (40 + extraVinculum) + "\nH1013.1s-83.4,268,-264.1,840c-180.7,572,-277,876.3,-289,913c-4.7,4.7,-12.7,7,-24,7\ns-12,0,-12,0c-1.3,-3.3,-3.7,-11.7,-7,-25c-35.3,-125.3,-106.7,-373.3,-214,-744\nc-10,12,-21,25,-33,39s-32,39,-32,39c-6,-5.3,-15,-14,-27,-26s25,-30,25,-30\nc26.7,-32.7,52,-63,76,-91s52,-60,52,-60s208,722,208,722\nc56,-175.3,126.3,-397.3,211,-666c84.7,-268.7,153.8,-488.2,207.5,-658.5\nc53.7,-170.3,84.5,-266.8,92.5,-289.5z\nM" + (1001 + extraVinculum) + " " + hLinePad + "h400000v" + (40 + extraVinculum) + "h-400000z"; }; -var sqrtSize3 = function sqrtSize3(extraViniculum, hLinePad) { +var sqrtSize3 = function sqrtSize3(extraVinculum, hLinePad) { // size3 is from glyph U221A in the font KaTeX_Size3-Regular - return "M424," + (2398 + extraViniculum + hLinePad) + "\nc-1.3,-0.7,-38.5,-172,-111.5,-514c-73,-342,-109.8,-513.3,-110.5,-514\nc0,-2,-10.7,14.3,-32,49c-4.7,7.3,-9.8,15.7,-15.5,25c-5.7,9.3,-9.8,16,-12.5,20\ns-5,7,-5,7c-4,-3.3,-8.3,-7.7,-13,-13s-13,-13,-13,-13s76,-122,76,-122s77,-121,77,-121\ns209,968,209,968c0,-2,84.7,-361.7,254,-1079c169.3,-717.3,254.7,-1077.7,256,-1081\nl" + extraViniculum / 4.223 + " -" + extraViniculum + "c4,-6.7,10,-10,18,-10 H400000\nv" + (40 + extraViniculum) + "H1014.6\ns-87.3,378.7,-272.6,1166c-185.3,787.3,-279.3,1182.3,-282,1185\nc-2,6,-10,9,-24,9\nc-8,0,-12,-0.7,-12,-2z M" + (1001 + extraViniculum) + " " + hLinePad + "\nh400000v" + (40 + extraViniculum) + "h-400000z"; + return "M424," + (2398 + extraVinculum + hLinePad) + "\nc-1.3,-0.7,-38.5,-172,-111.5,-514c-73,-342,-109.8,-513.3,-110.5,-514\nc0,-2,-10.7,14.3,-32,49c-4.7,7.3,-9.8,15.7,-15.5,25c-5.7,9.3,-9.8,16,-12.5,20\ns-5,7,-5,7c-4,-3.3,-8.3,-7.7,-13,-13s-13,-13,-13,-13s76,-122,76,-122s77,-121,77,-121\ns209,968,209,968c0,-2,84.7,-361.7,254,-1079c169.3,-717.3,254.7,-1077.7,256,-1081\nl" + extraVinculum / 4.223 + " -" + extraVinculum + "c4,-6.7,10,-10,18,-10 H400000\nv" + (40 + extraVinculum) + "H1014.6\ns-87.3,378.7,-272.6,1166c-185.3,787.3,-279.3,1182.3,-282,1185\nc-2,6,-10,9,-24,9\nc-8,0,-12,-0.7,-12,-2z M" + (1001 + extraVinculum) + " " + hLinePad + "\nh400000v" + (40 + extraVinculum) + "h-400000z"; }; -var sqrtSize4 = function sqrtSize4(extraViniculum, hLinePad) { +var sqrtSize4 = function sqrtSize4(extraVinculum, hLinePad) { // size4 is from glyph U221A in the font KaTeX_Size4-Regular - return "M473," + (2713 + extraViniculum + hLinePad) + "\nc339.3,-1799.3,509.3,-2700,510,-2702 l" + extraViniculum / 5.298 + " -" + extraViniculum + "\nc3.3,-7.3,9.3,-11,18,-11 H400000v" + (40 + extraViniculum) + "H1017.7\ns-90.5,478,-276.2,1466c-185.7,988,-279.5,1483,-281.5,1485c-2,6,-10,9,-24,9\nc-8,0,-12,-0.7,-12,-2c0,-1.3,-5.3,-32,-16,-92c-50.7,-293.3,-119.7,-693.3,-207,-1200\nc0,-1.3,-5.3,8.7,-16,30c-10.7,21.3,-21.3,42.7,-32,64s-16,33,-16,33s-26,-26,-26,-26\ns76,-153,76,-153s77,-151,77,-151c0.7,0.7,35.7,202,105,604c67.3,400.7,102,602.7,104,\n606zM" + (1001 + extraViniculum) + " " + hLinePad + "h400000v" + (40 + extraViniculum) + "H1017.7z"; + return "M473," + (2713 + extraVinculum + hLinePad) + "\nc339.3,-1799.3,509.3,-2700,510,-2702 l" + extraVinculum / 5.298 + " -" + extraVinculum + "\nc3.3,-7.3,9.3,-11,18,-11 H400000v" + (40 + extraVinculum) + "H1017.7\ns-90.5,478,-276.2,1466c-185.7,988,-279.5,1483,-281.5,1485c-2,6,-10,9,-24,9\nc-8,0,-12,-0.7,-12,-2c0,-1.3,-5.3,-32,-16,-92c-50.7,-293.3,-119.7,-693.3,-207,-1200\nc0,-1.3,-5.3,8.7,-16,30c-10.7,21.3,-21.3,42.7,-32,64s-16,33,-16,33s-26,-26,-26,-26\ns76,-153,76,-153s77,-151,77,-151c0.7,0.7,35.7,202,105,604c67.3,400.7,102,602.7,104,\n606zM" + (1001 + extraVinculum) + " " + hLinePad + "h400000v" + (40 + extraVinculum) + "H1017.7z"; }; var phasePath = function phasePath(y) { @@ -779,43 +791,43 @@ var phasePath = function phasePath(y) { return "M400000 " + y + " H0 L" + x + " 0 l65 45 L145 " + (y - 80) + " H400000z"; }; -var sqrtTall = function sqrtTall(extraViniculum, hLinePad, viewBoxHeight) { +var sqrtTall = function sqrtTall(extraVinculum, hLinePad, viewBoxHeight) { // sqrtTall is from glyph U23B7 in the font KaTeX_Size4-Regular - // One path edge has a variable length. It runs vertically from the viniculumn - // to a point near (14 units) the bottom of the surd. The viniculum + // One path edge has a variable length. It runs vertically from the vinculum + // to a point near (14 units) the bottom of the surd. The vinculum // is normally 40 units thick. So the length of the line in question is: - var vertSegment = viewBoxHeight - 54 - hLinePad - extraViniculum; - return "M702 " + (extraViniculum + hLinePad) + "H400000" + (40 + extraViniculum) + "\nH742v" + vertSegment + "l-4 4-4 4c-.667.7 -2 1.5-4 2.5s-4.167 1.833-6.5 2.5-5.5 1-9.5 1\nh-12l-28-84c-16.667-52-96.667 -294.333-240-727l-212 -643 -85 170\nc-4-3.333-8.333-7.667-13 -13l-13-13l77-155 77-156c66 199.333 139 419.667\n219 661 l218 661zM702 " + hLinePad + "H400000v" + (40 + extraViniculum) + "H742z"; + var vertSegment = viewBoxHeight - 54 - hLinePad - extraVinculum; + return "M702 " + (extraVinculum + hLinePad) + "H400000" + (40 + extraVinculum) + "\nH742v" + vertSegment + "l-4 4-4 4c-.667.7 -2 1.5-4 2.5s-4.167 1.833-6.5 2.5-5.5 1-9.5 1\nh-12l-28-84c-16.667-52-96.667 -294.333-240-727l-212 -643 -85 170\nc-4-3.333-8.333-7.667-13 -13l-13-13l77-155 77-156c66 199.333 139 419.667\n219 661 l218 661zM702 " + hLinePad + "H400000v" + (40 + extraVinculum) + "H742z"; }; -var sqrtPath = function sqrtPath(size, extraViniculum, viewBoxHeight) { - extraViniculum = 1000 * extraViniculum; // Convert from document ems to viewBox. +var sqrtPath = function sqrtPath(size, extraVinculum, viewBoxHeight) { + extraVinculum = 1000 * extraVinculum; // Convert from document ems to viewBox. var path = ""; switch (size) { case "sqrtMain": - path = sqrtMain(extraViniculum, hLinePad); + path = sqrtMain(extraVinculum, hLinePad); break; case "sqrtSize1": - path = sqrtSize1(extraViniculum, hLinePad); + path = sqrtSize1(extraVinculum, hLinePad); break; case "sqrtSize2": - path = sqrtSize2(extraViniculum, hLinePad); + path = sqrtSize2(extraVinculum, hLinePad); break; case "sqrtSize3": - path = sqrtSize3(extraViniculum, hLinePad); + path = sqrtSize3(extraVinculum, hLinePad); break; case "sqrtSize4": - path = sqrtSize4(extraViniculum, hLinePad); + path = sqrtSize4(extraVinculum, hLinePad); break; case "sqrtTall": - path = sqrtTall(extraViniculum, hLinePad, viewBoxHeight); + path = sqrtTall(extraVinculum, hLinePad, viewBoxHeight); } return path; @@ -921,7 +933,7 @@ var path = { widecheck4: "M1181,340h2l1171,-296c6,0,10,-5,10,-11l-2,-23c-1,-6,-5,-10,\n-11,-10h-1l-1168,273l-1167,-273h-1c-6,0,-10,4,-11,10l-2,23c-1,6,4,11,10,11z", // The next ten paths support reaction arrows from the mhchem package. // Arrows for \ce{<-->} are offset from xAxis by 0.22ex, per mhchem in LaTeX - // baraboveleftarrow is mostly from from glyph U+2190 in font KaTeX Main + // baraboveleftarrow is mostly from glyph U+2190 in font KaTeX Main baraboveleftarrow: "M400000 620h-399890l3 -3c68.7 -52.7 113.7 -120 135 -202\nc4 -14.7 6 -23 6 -25c0 -7.3 -7 -11 -21 -11c-8 0 -13.2 0.8 -15.5 2.5\nc-2.3 1.7 -4.2 5.8 -5.5 12.5c-1.3 4.7 -2.7 10.3 -4 17c-12 48.7 -34.8 92 -68.5 130\ns-74.2 66.3 -121.5 85c-10 4 -16 7.7 -18 11c0 8.7 6 14.3 18 17c47.3 18.7 87.8 47\n121.5 85s56.5 81.3 68.5 130c0.7 2 1.3 5 2 9s1.2 6.7 1.5 8c0.3 1.3 1 3.3 2 6\ns2.2 4.5 3.5 5.5c1.3 1 3.3 1.8 6 2.5s6 1 10 1c14 0 21 -3.7 21 -11\nc0 -2 -2 -10.3 -6 -25c-20 -79.3 -65 -146.7 -135 -202l-3 -3h399890z\nM100 620v40h399900v-40z M0 241v40h399900v-40zM0 241v40h399900v-40z", // rightarrowabovebar is mostly from glyph U+2192, KaTeX Main rightarrowabovebar: "M0 241v40h399891c-47.3 35.3-84 78-110 128-16.7 32\n-27.7 63.7-33 95 0 1.3-.2 2.7-.5 4-.3 1.3-.5 2.3-.5 3 0 7.3 6.7 11 20 11 8 0\n13.2-.8 15.5-2.5 2.3-1.7 4.2-5.5 5.5-11.5 2-13.3 5.7-27 11-41 14.7-44.7 39\n-84.5 73-119.5s73.7-60.2 119-75.5c6-2 9-5.7 9-11s-3-9-9-11c-45.3-15.3-85-40.5\n-119-75.5s-58.3-74.8-73-119.5c-4.7-14-8.3-27.3-11-40-1.3-6.7-3.2-10.8-5.5\n-12.5-2.3-1.7-7.5-2.5-15.5-2.5-14 0-21 3.7-21 11 0 2 2 10.3 6 25 20.7 83.3 67\n151.7 139 205zm96 379h399894v40H0zm0 0h399904v40H0z", @@ -3133,9 +3145,9 @@ var DocumentFragment = /*#__PURE__*/function () { // In TeX, there are actually three sets of dimensions, one for each of // textstyle (size index 5 and higher: >=9pt), scriptstyle (size index 3 and 4: // 7-8pt), and scriptscriptstyle (size index 1 and 2: 5-6pt). These are -// provided in the the arrays below, in that order. +// provided in the arrays below, in that order. // -// The font metrics are stored in fonts cmsy10, cmsy7, and cmsy5 respsectively. +// The font metrics are stored in fonts cmsy10, cmsy7, and cmsy5 respectively. // This was determined by running the following script: // // latex -interaction=nonstopmode \ @@ -3145,7 +3157,7 @@ var DocumentFragment = /*#__PURE__*/function () { // '\expandafter\show\the\scriptscriptfont2' \ // '\stop' // -// The metrics themselves were retreived using the following commands: +// The metrics themselves were retrieved using the following commands: // // tftopl cmsy10 // tftopl cmsy7 @@ -3357,7 +3369,7 @@ function getCharacterMetrics(character, font, mode) { // So if the character is in a script we support but we // don't have metrics for it, just use the metrics for // the Latin capital letter M. This is close enough because - // we (currently) only care about the height of the glpyh + // we (currently) only care about the height of the glyph // not its width. if (supportedCodepoint(ch)) { metrics = fontMetricsData[font][77]; // 77 is the charcode for 'M' @@ -6629,7 +6641,7 @@ function buildHTML(tree, options) { * since we're mainly using MathML to improve accessibility, we don't manage * any of the styling state that the plain DOM nodes do. * - * The `toNode` and `toMarkup` functions work simlarly to how they do in + * The `toNode` and `toMarkup` functions work similarly to how they do in * domTree.js, creating namespaced DOM nodes and HTML text markup respectively. */ @@ -6771,7 +6783,7 @@ var TextNode = /*#__PURE__*/function () { } /** * Converts the text node into a string - * (representing the text iteself). + * (representing the text itself). */ ; @@ -6870,7 +6882,7 @@ var SpaceNode = /*#__PURE__*/function () { }); ;// CONCATENATED MODULE: ./src/buildMathML.js /** - * This file converts a parse tree into a cooresponding MathML tree. The main + * This file converts a parse tree into a corresponding MathML tree. The main * entry point is the `buildMathML` function, which takes a parse tree from the * parser. */ @@ -6953,7 +6965,7 @@ var getVariant = function getVariant(group, options) { } else if (font === "mathfrak") { return "fraktur"; } else if (font === "mathscr" || font === "mathcal") { - // MathML makes no distinction between script and caligrahpic + // MathML makes no distinction between script and calligraphic return "script"; } else if (font === "mathsf") { return "sans-serif"; @@ -7914,7 +7926,7 @@ defineFunction({ }; }, // Flow is unable to correctly infer the type of `group`, even though it's - // unamibiguously determined from the passed-in `type` above. + // unambiguously determined from the passed-in `type` above. htmlBuilder: function htmlBuilder(group, options) { var style = options.style; // Build the argument groups in the appropriate style. // Ref: amsmath.dtx: \hbox{$\scriptstyle\mkern#3mu{#6}\mkern#4mu$}% @@ -9259,7 +9271,7 @@ var makeStackedDelim = function makeStackedDelim(delim, heightTotal, center, opt var middleMetrics = getMetrics(middle, font, mode); middleHeightTotal = middleMetrics.height + middleMetrics.depth; middleFactor = 2; // repeat symmetrically above and below middle - } // Calcuate the minimal height that the delimiter can have. + } // Calculate the minimal height that the delimiter can have. // It is at least the size of the top, bottom, and optional middle combined. @@ -9343,7 +9355,7 @@ var makeStackedDelim = function makeStackedDelim(delim, heightTotal, center, opt children: stack }, newOptions); return styleWrap(buildCommon.makeSpan(["delimsizing", "mult"], [inner], newOptions), src_Style.TEXT, options, classes); -}; // All surds have 0.08em padding above the viniculum inside the SVG. +}; // All surds have 0.08em padding above the vinculum inside the SVG. // That keeps browser span height rounding error from pinching the line. @@ -9351,8 +9363,8 @@ var vbPad = 80; // padding above the surd, measured inside the viewBox. var emPad = 0.08; // padding, in ems, measured in the document. -var sqrtSvg = function sqrtSvg(sqrtName, height, viewBoxHeight, extraViniculum, options) { - var path = sqrtPath(sqrtName, extraViniculum, viewBoxHeight); +var sqrtSvg = function sqrtSvg(sqrtName, height, viewBoxHeight, extraVinculum, options) { + var path = sqrtPath(sqrtName, extraVinculum, viewBoxHeight); var pathNode = new PathNode(sqrtName, path); var svg = new SvgNode([pathNode], { // Note: 1000:1 ratio of viewBox to document em width. @@ -9375,10 +9387,10 @@ var makeSqrtImage = function makeSqrtImage(height, options) { var delim = traverseSequence("\\surd", height * newOptions.sizeMultiplier, stackLargeDelimiterSequence, newOptions); var sizeMultiplier = newOptions.sizeMultiplier; // default - // The standard sqrt SVGs each have a 0.04em thick viniculum. - // If Settings.minRuleThickness is larger than that, we add extraViniculum. + // The standard sqrt SVGs each have a 0.04em thick vinculum. + // If Settings.minRuleThickness is larger than that, we add extraVinculum. - var extraViniculum = Math.max(0, options.minRuleThickness - options.fontMetrics().sqrtRuleThickness); // Create a span containing an SVG image of a sqrt symbol. + var extraVinculum = Math.max(0, options.minRuleThickness - options.fontMetrics().sqrtRuleThickness); // Create a span containing an SVG image of a sqrt symbol. var span; var spanHeight = 0; @@ -9386,14 +9398,14 @@ var makeSqrtImage = function makeSqrtImage(height, options) { var viewBoxHeight = 0; var advanceWidth; // We create viewBoxes with 80 units of "padding" above each surd. // Then browser rounding error on the parent span height will not - // encroach on the ink of the viniculum. But that padding is not + // encroach on the ink of the vinculum. But that padding is not // included in the TeX-like `height` used for calculation of // vertical alignment. So texHeight = span.height < span.style.height. if (delim.type === "small") { // Get an SVG that is derived from glyph U+221A in font KaTeX-Main. // 1000 unit normal glyph height. - viewBoxHeight = 1000 + 1000 * extraViniculum + vbPad; + viewBoxHeight = 1000 + 1000 * extraVinculum + vbPad; if (height < 1.0) { sizeMultiplier = 1.0; // mimic a \textfont radical @@ -9401,26 +9413,26 @@ var makeSqrtImage = function makeSqrtImage(height, options) { sizeMultiplier = 0.7; // mimic a \scriptfont radical } - spanHeight = (1.0 + extraViniculum + emPad) / sizeMultiplier; - texHeight = (1.00 + extraViniculum) / sizeMultiplier; - span = sqrtSvg("sqrtMain", spanHeight, viewBoxHeight, extraViniculum, options); + spanHeight = (1.0 + extraVinculum + emPad) / sizeMultiplier; + texHeight = (1.00 + extraVinculum) / sizeMultiplier; + span = sqrtSvg("sqrtMain", spanHeight, viewBoxHeight, extraVinculum, options); span.style.minWidth = "0.853em"; advanceWidth = 0.833 / sizeMultiplier; // from the font. } else if (delim.type === "large") { // These SVGs come from fonts: KaTeX_Size1, _Size2, etc. viewBoxHeight = (1000 + vbPad) * sizeToMaxHeight[delim.size]; - texHeight = (sizeToMaxHeight[delim.size] + extraViniculum) / sizeMultiplier; - spanHeight = (sizeToMaxHeight[delim.size] + extraViniculum + emPad) / sizeMultiplier; - span = sqrtSvg("sqrtSize" + delim.size, spanHeight, viewBoxHeight, extraViniculum, options); + texHeight = (sizeToMaxHeight[delim.size] + extraVinculum) / sizeMultiplier; + spanHeight = (sizeToMaxHeight[delim.size] + extraVinculum + emPad) / sizeMultiplier; + span = sqrtSvg("sqrtSize" + delim.size, spanHeight, viewBoxHeight, extraVinculum, options); span.style.minWidth = "1.02em"; advanceWidth = 1.0 / sizeMultiplier; // 1.0 from the font. } else { // Tall sqrt. In TeX, this would be stacked using multiple glyphs. // We'll use a single SVG to accomplish the same thing. - spanHeight = height + extraViniculum + emPad; - texHeight = height + extraViniculum; - viewBoxHeight = Math.floor(1000 * height + extraViniculum) + vbPad; - span = sqrtSvg("sqrtTall", spanHeight, viewBoxHeight, extraViniculum, options); + spanHeight = height + extraVinculum + emPad; + texHeight = height + extraVinculum; + viewBoxHeight = Math.floor(1000 * height + extraVinculum) + vbPad; + span = sqrtSvg("sqrtTall", spanHeight, viewBoxHeight, extraVinculum, options); span.style.minWidth = "0.742em"; advanceWidth = 1.056; } @@ -9434,7 +9446,7 @@ var makeSqrtImage = function makeSqrtImage(height, options) { // This actually should depend on the chosen font -- e.g. \boldmath // should use the thicker surd symbols from e.g. KaTeX_Main-Bold, and // have thicker rules. - ruleWidth: (options.fontMetrics().sqrtRuleThickness + extraViniculum) * sizeMultiplier + ruleWidth: (options.fontMetrics().sqrtRuleThickness + extraVinculum) * sizeMultiplier }; }; // There are three kinds of delimiters, delimiters that stack when they become // too large @@ -10011,7 +10023,7 @@ defineFunction({ return middleDelim; }, mathmlBuilder: function mathmlBuilder(group, options) { - // A Firefox \middle will strech a character vertically only if it + // A Firefox \middle will stretch a character vertically only if it // is in the fence part of the operator dictionary at: // https://www.w3.org/TR/MathML3/appendixc.html. // So we need to avoid U+2223 and use plain "|" instead. @@ -11080,8 +11092,8 @@ var array_mathmlBuilder = function mathmlBuilder(group, options) { // LaTeX \arraystretch multiplies the row baseline-to-baseline distance. // We simulate this by adding (arraystretch - 1)em to the gap. This // does a reasonable job of adjusting arrays containing 1 em tall content. - // The 0.16 and 0.09 values are found emprically. They produce an array - // similar to LaTeX and in which content does not interfere with \hines. + // The 0.16 and 0.09 values are found empirically. They produce an array + // similar to LaTeX and in which content does not interfere with \hlines. var gap = group.arraystretch === 0.5 ? 0.1 // {smallmatrix}, {subarray} : 0.16 + group.arraystretch - 1 + (group.addJot ? 0.09 : 0); @@ -16668,15 +16680,15 @@ var MacroExpander = /*#__PURE__*/function () { * Expand the next token only once if possible. * * If the token is expanded, the resulting tokens will be pushed onto - * the stack in reverse order and will be returned as an array, - * also in reverse order. + * the stack in reverse order, and the number of such tokens will be + * returned. This number might be zero or positive. * - * If not, the next token will be returned without removing it - * from the stack. This case can be detected by a `Token` return value - * instead of an `Array` return value. + * If not, the return value is `false`, and the next token remains at the + * top of the stack. * * In either case, the next token will be on the top of the stack, - * or the stack will be empty. + * or the stack will be empty (in case of empty expansion + * and no other tokens). * * Used to implement `expandAfterFuture` and `expandNextToken`. * @@ -16696,7 +16708,7 @@ var MacroExpander = /*#__PURE__*/function () { } this.pushToken(topToken); - return topToken; + return false; } this.expansionCount++; @@ -16739,7 +16751,7 @@ var MacroExpander = /*#__PURE__*/function () { this.pushTokens(tokens); - return tokens; + return tokens.length; } /** * Expand the next token only once (if possible), and return the resulting @@ -16760,16 +16772,16 @@ var MacroExpander = /*#__PURE__*/function () { _proto.expandNextToken = function expandNextToken() { for (;;) { - var expanded = this.expandOnce(); // expandOnce returns Token if and only if it's fully expanded. - - if (expanded instanceof Token) { - // the token after \noexpand is interpreted as if its meaning + if (this.expandOnce() === false) { + // fully expanded + var token = this.stack.pop(); // the token after \noexpand is interpreted as if its meaning // were ‘\relax’ - if (expanded.treatAsRelax) { - expanded.text = "\\relax"; + + if (token.treatAsRelax) { + token.text = "\\relax"; } - return this.stack.pop(); // === expanded + return token; } } // Flow unable to figure out that this pathway is impossible. // https://github.com/facebook/flow/issues/4808 @@ -16799,17 +16811,18 @@ var MacroExpander = /*#__PURE__*/function () { this.pushTokens(tokens); while (this.stack.length > oldStackLength) { - var expanded = this.expandOnce(true); // expand only expandable tokens - // expandOnce returns Token if and only if it's fully expanded. + // Expand only expandable tokens + if (this.expandOnce(true) === false) { + // fully expanded + var token = this.stack.pop(); - if (expanded instanceof Token) { - if (expanded.treatAsRelax) { + if (token.treatAsRelax) { // the expansion of \noexpand is the token itself - expanded.noexpand = false; - expanded.treatAsRelax = false; + token.noexpand = false; + token.treatAsRelax = false; } - output.push(this.stack.pop()); + output.push(token); } } @@ -17586,7 +17599,7 @@ var Parser = /*#__PURE__*/function () { * Parses an "expression", which is a list of atoms. * * `breakOnInfix`: Should the parsing stop when we hit infix nodes? This - * happens when functions have higher precendence han infix + * happens when functions have higher precedence han infix * nodes in implicit parses. * * `breakOnTokenText`: The text of the token that the expression should end @@ -18600,6 +18613,7 @@ var parseTree = function parseTree(toParse, settings) { + /** * Parse and build an expression, and place that expression in the DOM node * given. @@ -18693,7 +18707,7 @@ var renderToHTMLTree = function renderToHTMLTree(expression, options) { /** * Current KaTeX version */ - version: "0.16.4", + version: "0.16.8", /** * Renders the given LaTeX into an HTML+MathML combination, and adds @@ -18758,6 +18772,13 @@ var renderToHTMLTree = function renderToHTMLTree(expression, options) { */ __defineSymbol: defineSymbol, + /** + * adds a new function to builtin function list, + * which directly produce parse tree elements + * and have their own html/mathml builders + */ + __defineFunction: defineFunction, + /** * adds a new macro to builtin macro list */ diff --git a/assets/ts/modules/swup.js b/assets/ts/modules/swup.js index b6d1178d..0511fcd1 100644 --- a/assets/ts/modules/swup.js +++ b/assets/ts/modules/swup.js @@ -1,2 +1,2 @@ -!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):(t||self).Swup=e()}(this,function(){const t=function(t){let{hash:e}=void 0===t?{}:t;return location.pathname+location.search+(e?location.hash:"")},e=function(e,n){void 0===e&&(e=null),void 0===n&&(n={}),e=e||t({hash:!0});const i={...history.state,url:e,random:Math.random(),source:"swup",...n};history.replaceState(i,"",e)},n=new WeakMap;function i(t,e,i,s){var o,r;if(!t&&!n.has(e))return!1;const a=null!==(o=n.get(e))&&void 0!==o?o:new WeakMap;if(n.set(e,a),!t&&!n.has(e))return!1;const l=null!==(r=a.get(i))&&void 0!==r?r:new Set;a.set(i,l);const c=l.has(s);return t?l.add(s):l.delete(s),c&&t}function s(t,e,n,o,r){if("string"==typeof t&&(t=document.querySelectorAll(t)),"function"!=typeof t.addEventListener){const i=Array.prototype.map.call(t,t=>s(t,e,n,o,r));return{destroy(){for(const t of i)t.destroy()}}}const a=t instanceof Document?t.documentElement:t,l=Boolean("object"==typeof r?r.capture:r),c=t=>{const n=function(t,e){let n=t.target;if(n instanceof Text&&(n=n.parentElement),n instanceof Element&&t.currentTarget instanceof Element){const i=n.closest(e);if(i&&t.currentTarget.contains(i))return i}}(t,e);n&&(t.delegateTarget=n,o.call(a,t))};"object"==typeof r&&delete r.once;const u=JSON.stringify({selector:e,type:n,capture:l}),h={destroy(){a.removeEventListener(n,c,r),i(!1,a,o,u)}};return i(!0,a,o,u)||a.addEventListener(n,c,r),h}const o=function(t,e,n,i){let{base:o=document,...r}=void 0===i?{}:i;const a=s(o,t,e,n,r);return{destroy:()=>a.destroy()}},r=function(t,e){return void 0===e&&(e=document),e.querySelector(t)},a=function(t,e){return void 0===e&&(e=document),Array.from(e.querySelectorAll(t))},l=t=>1e3*Number(t.slice(0,-1).replace(",","."));class c extends URL{constructor(t,e){void 0===e&&(e=document.baseURI),super(t.toString(),e)}get url(){return this.pathname+this.search}static fromElement(t){const e=t.getAttribute("href")||t.getAttribute("xlink:href");return new c(e)}static fromUrl(t){return new c(t)}}const u=t=>/^to-/.test(t)||["is-changing","is-rendering","is-popstate"].includes(t),h=()=>{const t=document.documentElement.className.split(" ").filter(u);document.documentElement.classList.remove(...t)};class d{constructor(t){this.pages={},this.last=null,this.swup=void 0,this.swup=t}getCacheUrl(t){return this.swup.resolveUrl(c.fromUrl(t).url)}cacheUrl(t){t.url=this.getCacheUrl(t.url),t.url in this.pages==0&&(this.pages[t.url]=t),t.responseURL=this.getCacheUrl(t.responseURL),this.last=this.pages[t.url],this.swup.log(`Cache (${Object.keys(this.pages).length})`,this.pages)}getPage(t){return t=this.getCacheUrl(t),this.pages[t]}getCurrentPage(){return this.getPage(t())}exists(t){return(t=this.getCacheUrl(t))in this.pages}empty(){this.pages={},this.last=null,this.swup.log("Cache cleared")}remove(t){delete this.pages[this.getCacheUrl(t)]}}const p=function(t){let{event:e,skipTransition:n}=void 0===t?{}:t;if(n)return this.triggerEvent("transitionEnd",e),this.cleanupAnimationClasses(),[Promise.resolve()];var i;i=()=>{this.triggerEvent("animationInStart"),document.documentElement.classList.remove("is-animating")},requestAnimationFrame(()=>{requestAnimationFrame(()=>{i()})});const s=this.getAnimationPromises("in");return Promise.all(s).then(()=>{this.triggerEvent("animationInDone"),this.triggerEvent("transitionEnd",e),this.cleanupAnimationClasses()}),s},g=t=>{return t?("#"===t.charAt(0)&&(t=t.substring(1)),e=t=decodeURIComponent(t),t=window.CSS&&window.CSS.escape?CSS.escape(e):e,r(`#${t}`)||r(`a[name='${t}']`)):null;var e};let m="transition",f="transitionend",v="animation",w="animationend";function E(t){const e=this.options.animationSelector;if(!1===e)return[Promise.resolve()];const n=a(e,document.body);return n.length?n.map(t=>function(t,e,n){void 0===n&&(n=null);const{type:i,timeout:s,propCount:o}=function(t,e){void 0===e&&(e=null);const n=window.getComputedStyle(t),i=`${m}Duration`,s=`${v}Delay`,o=`${v}Duration`,r=n[`${m}Delay`].split(", "),a=(n[i]||"").split(", "),l=P(r,a),c=(n[s]||"").split(", "),u=(n[o]||"").split(", "),h=P(c,u);let d="",p=0,g=0;return"transition"===e?l>0&&(d="transition",p=l,g=a.length):"animation"===e?h>0&&(d="animation",p=h,g=u.length):(p=Math.max(l,h),d=p>0?l>h?"transition":"animation":null,g=d?"transition"===d?a.length:u.length:0),{type:d,timeout:p,propCount:g}}(t,n);return i&&s?new Promise(e=>{const n="transition"===i?f:w,r=performance.now();let a=0;const l=()=>{t.removeEventListener(n,c),e()},c=e=>{if(e.target===t){if(!(t=>!!t.elapsedTime)(e))throw new Error("Not a transition or animation event.");(performance.now()-r)/1e3=o&&l()}};setTimeout(()=>{al(e)+l(t[n])))}void 0===window.ontransitionend&&void 0!==window.onwebkittransitionend&&(m="WebkitTransition",f="webkitTransitionEnd"),void 0===window.onanimationend&&void 0!==window.onwebkitanimationend&&(v="WebkitAnimation",w="webkitAnimationEnd");const S=function(t){const e=((t,e)=>{let n=document.createElement("html");n.innerHTML=t;let i=[];e.forEach(t=>{if(null==r(t,n))return console.warn(`[swup] Container ${t} not found on page.`),null;a(t).length!==a(t,n).length&&console.warn("[swup] Mismatched number of containers found on new page."),a(t).forEach((e,s)=>{a(t,n)[s].setAttribute("data-swup",String(i.length)),i.push(a(t,n)[s].outerHTML)})});const s=r("title",n)?.innerText||"",o=r("body",n)?.className;return n.innerHTML="",n=null,{title:s,pageClass:o,blocks:i,originalContent:t}})(t.responseText,this.options.containers);return e?{...e,responseURL:t.responseURL||window.location.href}:(console.warn("[swup] Received page is invalid."),null)};function y(t){const e=this.options.requestHeaders,{url:n}=t;return this.cache.exists(n)?(this.triggerEvent("pageRetrievedFromCache"),Promise.resolve(this.cache.getPage(n))):new Promise((i,s)=>{((t,e)=>{const n={url:window.location.pathname+window.location.search,method:"GET",data:null,headers:{}},{url:i,method:s,headers:o,data:r}={...n,...t},a=new XMLHttpRequest;a.onreadystatechange=function(){4===a.readyState&&e(a)},a.open(s,i,!0),Object.entries(o).forEach(t=>{let[e,n]=t;a.setRequestHeader(e,n)}),a.send(r)})({...t,headers:e},t=>{if(500===t.status)return this.triggerEvent("serverError"),void s(n);const e=this.getPageData(t);if(!e||!e.blocks.length)return void s(n);const o={...e,url:n};this.cache.cacheUrl(o),this.triggerEvent("pageLoaded"),i(o)})})}const b=function(t){let{event:e,skipTransition:n}=void 0===t?{}:t;const i=e instanceof PopStateEvent;if(n)return this.triggerEvent("animationSkipped"),[Promise.resolve()];this.triggerEvent("animationOutStart"),document.documentElement.classList.add("is-changing","is-leaving","is-animating"),i&&document.documentElement.classList.add("is-popstate");const s=this.getAnimationPromises("out");return Promise.all(s).then(()=>{this.triggerEvent("animationOutDone")}),s};function k(t){const{url:e}=t;this.shouldIgnoreVisit(e)?window.location.href=e:this.performPageLoad(t)}function U(e){const{url:n,event:i,customTransition:s}=e??{},o=i instanceof PopStateEvent,r=this.shouldSkipTransition({url:n,event:i});var a;this.triggerEvent("transitionStart",i),this.updateTransition(t(),n,s),null!=s&&document.documentElement.classList.add(`to-${a=s,String(a).toLowerCase().replace(/[\s/_.]+/g,"-").replace(/[^\w-]+/g,"").replace(/--+/g,"-").replace(/^-+|-+$/g,"")||""}`);const l=this.leavePage({event:i,skipTransition:r});o||function(e,n){void 0===n&&(n={});const i={url:e=e||t({hash:!0}),random:Math.random(),source:"swup",...n};history.pushState(i,"",e)}(n+(this.scrollToElement||"")),this.currentPageUrl=t();const c=this.fetchPage(e);Promise.all([c,...l]).then(t=>{let[e]=t;this.renderPage(e,{event:i,skipTransition:r})}).catch(t=>{void 0!==t&&(this.options.skipPopStateHandling=()=>(window.location=t,!0),history.go(-1))})}const L=function(t){let{blocks:e,title:n}=t;return e.forEach((t,e)=>{document.body.querySelector(`[data-swup="${e}"]`).outerHTML=t}),document.title=n,Promise.resolve()};function T(t,e){const n=this._handlers[t];n?n.push(e):console.warn(`Unsupported event ${t}.`)}function C(t,e){if(t&&e){const n=this._handlers[t];n.includes(e)?this._handlers[t]=n.filter(t=>t!==e):console.warn(`Handler for event '${t}' not found.`)}else t?this._handlers[t]=[]:Object.keys(this._handlers).forEach(t=>{this._handlers[t]=[]})}function H(t,e){this._handlers[t].forEach(t=>{try{t(e)}catch(t){console.error(t)}});const n=new CustomEvent(`swup:${t}`,{detail:t});document.dispatchEvent(n)}const R=function(t){if(t?.isSwupPlugin){if(t.swup=this,!t._checkRequirements||t._checkRequirements())return t._beforeMount&&t._beforeMount(),t.mount(),this.plugins.push(t),this.plugins}else console.error("Not a swup plugin instance",t)};function A(t){const e=this.findPlugin(t);if(e)return e.unmount(),e._afterUnmount&&e._afterUnmount(),this.plugins=this.plugins.filter(t=>t!==e),this.plugins;console.error("No such plugin",e)}function $(t){return this.plugins.find(e=>e===t||e.name===t)}const _=function(n,i){let{event:s,skipTransition:o}=void 0===i?{}:i;if(document.documentElement.classList.remove("is-leaving"),!this.isSameResolvedUrl(t(),n.url))return;const{url:r}=c.fromUrl(n.responseURL);this.isSameResolvedUrl(t(),r)||(this.cache.cacheUrl({...n,url:r}),this.currentPageUrl=t(),e(r)),o||document.documentElement.classList.add("is-rendering"),this.triggerEvent("willReplaceContent",s),this.replaceContent(n).then(()=>{this.triggerEvent("contentReplaced",s),this.triggerEvent("pageView",s),this.options.cache||this.cache.empty(),this.enterPage({event:s,skipTransition:o}),this.scrollToElement=null})};function x(t,e,n){this.transition={from:t,to:e,custom:n}}function M(t){let{event:e}=t;return!(!(e instanceof PopStateEvent)||this.options.animateHistoryBrowsing)}return class{constructor(e){void 0===e&&(e={}),this.version="3.0.4",this._handlers={animationInDone:[],animationInStart:[],animationOutDone:[],animationOutStart:[],animationSkipped:[],clickLink:[],contentReplaced:[],disabled:[],enabled:[],openPageInNewTab:[],pageLoaded:[],pageRetrievedFromCache:[],pageView:[],popState:[],samePage:[],samePageWithHash:[],serverError:[],transitionStart:[],transitionEnd:[],willReplaceContent:[]},this.scrollToElement=null,this.options=void 0,this.plugins=[],this.transition={},this.cache=void 0,this.currentPageUrl=t(),this.delegatedListeners={},this.boundPopStateHandler=void 0,this.loadPage=k,this.performPageLoad=U,this.leavePage=b,this.renderPage=_,this.replaceContent=L,this.enterPage=p,this.triggerEvent=H,this.delegateEvent=o,this.on=T,this.off=C,this.updateTransition=x,this.shouldSkipTransition=M,this.getAnimationPromises=E,this.getPageData=S,this.fetchPage=y,this.getAnchorElement=g,this.log=()=>{},this.use=R,this.unuse=A,this.findPlugin=$,this.getCurrentUrl=t,this.cleanupAnimationClasses=h,this.defaults={animateHistoryBrowsing:!1,animationSelector:'[class*="transition-"]',cache:!0,containers:["#swup"],ignoreVisit:function(t,e){let{el:n}=void 0===e?{}:e;return!!n?.closest("[data-no-swup]")},linkSelector:"a[href]",plugins:[],resolveUrl:t=>t,requestHeaders:{"X-Requested-With":"swup",Accept:"text/html, application/xhtml+xml"},skipPopStateHandling:t=>"swup"!==t.state?.source},this.options={...this.defaults,...e},this.boundPopStateHandler=this.popStateHandler.bind(this),this.cache=new d(this),this.enable()}enable(){"undefined"!=typeof Promise?(this.delegatedListeners.click=o(this.options.linkSelector,"click",this.linkClickHandler.bind(this)),window.addEventListener("popstate",this.boundPopStateHandler),((t,e)=>{let n=0;this.options.containers.forEach(e=>{null==r(e,t)?console.warn(`[swup] Container ${e} not found on page.`):a(e).forEach((i,s)=>{a(e,t)[s].setAttribute("data-swup",String(n)),n++})})})(document.documentElement),this.options.plugins.forEach(t=>this.use(t)),e(),this.triggerEvent("enabled"),document.documentElement.classList.add("swup-enabled"),this.triggerEvent("pageView")):console.warn("Promise is not supported")}destroy(){this.delegatedListeners.click.destroy(),window.removeEventListener("popstate",this.boundPopStateHandler),this.cache.empty(),this.options.plugins.forEach(t=>{this.unuse(t)}),a("[data-swup]").forEach(t=>{t.removeAttribute("data-swup")}),this.off(),this.triggerEvent("disabled"),document.documentElement.classList.remove("swup-enabled")}shouldIgnoreVisit(t,e){let{el:n}=void 0===e?{}:e;const{origin:i,url:s,hash:o}=c.fromUrl(t);return i!==window.location.origin||!(!n||!this.triggerWillOpenNewWindow(n))||!!this.options.ignoreVisit(s+o,{el:n})}linkClickHandler(e){const n=e.delegateTarget,{href:i,url:s,hash:o}=c.fromElement(n);if(this.shouldIgnoreVisit(i,{el:n}))return;if(e.metaKey||e.ctrlKey||e.shiftKey||e.altKey)return void this.triggerEvent("openPageInNewTab",e);if(0!==e.button)return;if(this.triggerEvent("clickLink",e),e.preventDefault(),!s||s===t())return void this.handleLinkToSamePage(s,o,e);if(this.isSameResolvedUrl(s,t()))return;this.scrollToElement=o||null;const r=n.getAttribute("data-swup-transition")||void 0;this.performPageLoad({url:s,customTransition:r})}handleLinkToSamePage(t,n,i){if(n){if(this.triggerEvent("samePageWithHash",i),!g(n))return console.warn(`Element for offset not found (#${n})`);e(t+n)}else this.triggerEvent("samePage",i)}triggerWillOpenNewWindow(t){return!!t.matches('[download], [target="_blank"]')}popStateHandler(e){if(this.options.skipPopStateHandling(e))return;if(this.isSameResolvedUrl(t(),this.currentPageUrl))return;const n=e.state?.url??location.href;if(this.shouldIgnoreVisit(n))return;const{url:i,hash:s}=c.fromUrl(n);s?this.scrollToElement=s:e.preventDefault(),this.triggerEvent("popState",e),this.options.animateHistoryBrowsing||(document.documentElement.classList.remove("is-animating"),h()),this.performPageLoad({url:i,event:e})}resolveUrl(t){if("function"!=typeof this.options.resolveUrl)return console.warn("[swup] options.resolveUrl expects a callback function."),t;const e=this.options.resolveUrl(t);return e&&"string"==typeof e?e.startsWith("//")||e.startsWith("http")?(console.warn("[swup] options.resolveUrl needs to return a relative url"),t):e:(console.warn("[swup] options.resolveUrl needs to return a url"),t)}isSameResolvedUrl(t,e){return this.resolveUrl(t)===this.resolveUrl(e)}}}); +!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):(t||self).Swup=e()}(this,function(){const t=(t,e)=>String(t).toLowerCase().replace(/[\s/_.]+/g,"-").replace(/[^\w-]+/g,"").replace(/--+/g,"-").replace(/^-+|-+$/g,"")||e||"",e=function(t){let{hash:e}=void 0===t?{}:t;return location.pathname+location.search+(e?location.hash:"")},n=function(t,n){void 0===n&&(n={});const r={url:t=t||e({hash:!0}),random:Math.random(),source:"swup",...n};history.pushState(r,"",t)},r=function(t,n){void 0===t&&(t=null),void 0===n&&(n={}),t=t||e({hash:!0});const r={...history.state||{},url:t,random:Math.random(),source:"swup",...n};history.replaceState(r,"",t)},o=new WeakMap;function i(t,e,n,r){if(!t&&!o.has(e))return!1;const i=o.get(e)??new WeakMap;o.set(e,i);const s=i.get(n)??new Set;i.set(n,s);const a=s.has(r);return t?s.add(r):s.delete(r),a&&t}const s=(t,e,n,r)=>{const o=new AbortController;return function(t,e,n,r={}){const{signal:o,base:s=document}=r;if(o?.aborted)return;const{once:a,...c}=r,l=s instanceof Document?s.documentElement:s,h=Boolean("object"==typeof r?r.capture:r),u=r=>{const o=function(t,e){let n=t.target;if(n instanceof Text&&(n=n.parentElement),n instanceof Element&&t.currentTarget instanceof Element){const r=n.closest(e);if(r&&t.currentTarget.contains(r))return r}}(r,t);if(o){const t=Object.assign(r,{delegateTarget:o});n.call(l,t),a&&(l.removeEventListener(e,u,c),i(!1,l,n,d))}},d=JSON.stringify({selector:t,type:e,capture:h});i(!0,l,n,d)||l.addEventListener(e,u,c),o?.addEventListener("abort",()=>{i(!1,l,n,d)})}(t,e,n,r={...r,signal:o.signal}),{destroy:()=>o.abort()}};class a extends URL{constructor(t,e){void 0===e&&(e=document.baseURI),super(t.toString(),e)}get url(){return this.pathname+this.search}static fromElement(t){const e=t.getAttribute("href")||t.getAttribute("xlink:href")||"";return new a(e)}static fromUrl(t){return new a(t)}}class c{constructor(t){this.swup=void 0,this.pages=new Map,this.swup=t}get size(){return this.pages.size}get all(){const t=new Map;return this.pages.forEach((e,n)=>{t.set(n,{...e})}),t}has(t){return this.pages.has(this.resolve(t))}get(t){const e=this.pages.get(this.resolve(t));return e?{...e}:e}set(t,e){t=this.resolve(t),e={...e,url:t},this.pages.set(t,e),this.swup.hooks.callSync("cache:set",{page:e})}update(t,e){t=this.resolve(t);const n={...this.get(t),...e,url:t};this.pages.set(t,n)}delete(t){this.pages.delete(this.resolve(t))}clear(){this.pages.clear(),this.swup.hooks.callSync("cache:clear",void 0)}prune(t){this.pages.forEach((e,n)=>{t(n,e)&&this.delete(n)})}resolve(t){const{url:e}=a.fromUrl(t);return this.swup.resolveUrl(e)}}const l=function(t,e){return void 0===e&&(e=document),e.querySelector(t)},h=function(t,e){return void 0===e&&(e=document),Array.from(e.querySelectorAll(t))},u=()=>new Promise(t=>{requestAnimationFrame(()=>{requestAnimationFrame(()=>{t()})})});function d(t){return!!t&&("object"==typeof t||"function"==typeof t)&&"function"==typeof t.then}const m=t=>window.CSS&&window.CSS.escape?CSS.escape(t):t,f=t=>1e3*Number(t.slice(0,-1).replace(",","."));class p{constructor(t){this.swup=void 0,this.swupClasses=["to-","is-changing","is-rendering","is-popstate","is-animating"],this.swup=t}get selectors(){const{scope:t}=this.swup.visit.animation;return"containers"===t?this.swup.visit.containers:"html"===t?["html"]:Array.isArray(t)?t:[]}get selector(){return this.selectors.join(",")}get targets(){return this.selector.trim()?h(this.selector):[]}add(){this.targets.forEach(t=>t.classList.add(...[].slice.call(arguments)))}remove(){this.targets.forEach(t=>t.classList.remove(...[].slice.call(arguments)))}clear(){this.targets.forEach(t=>{const e=t.className.split(" ").filter(t=>this.isSwupClass(t));t.classList.remove(...e)})}isSwupClass(t){return this.swupClasses.some(e=>t.startsWith(e))}}function v(t){let{to:e,from:n=this.currentPageUrl,hash:r,el:o,event:i}=t;return{id:Math.random(),from:{url:n},to:{url:e,hash:r},containers:this.options.containers,animation:{animate:!0,wait:!1,name:void 0,scope:this.options.animationScope,selector:this.options.animationSelector},trigger:{el:o,event:i},cache:{read:this.options.cache,write:this.options.cache},history:{action:"push",popstate:!1,direction:void 0},scroll:{reset:!0,target:void 0}}}const g="undefined"!=typeof Symbol?Symbol.iterator||(Symbol.iterator=Symbol("Symbol.iterator")):"@@iterator";function w(t,e,n){if(!t.s){if(n instanceof y){if(!n.s)return void(n.o=w.bind(null,t,e));1&e&&(e=n.s),n=n.v}if(n&&n.then)return void n.then(w.bind(null,t,e),w.bind(null,t,2));t.s=e,t.v=n;const r=t.o;r&&r(t)}}const y=/*#__PURE__*/function(){function t(){}return t.prototype.then=function(e,n){const r=new t,o=this.s;if(o){const t=1&o?e:n;if(t){try{w(r,1,t(this.v))}catch(t){w(r,2,t)}return r}return this}return this.o=function(t){try{const o=t.v;1&t.s?w(r,1,e?e(o):o):n?w(r,1,n(o)):w(r,2,o)}catch(t){w(r,2,t)}},r},t}();function P(t){return t instanceof y&&1&t.s}class k{constructor(t){this.swup=void 0,this.registry=new Map,this.hooks=["animation:out:start","animation:out:await","animation:out:end","animation:in:start","animation:in:await","animation:in:end","animation:skip","cache:clear","cache:set","content:replace","content:scroll","enable","disable","fetch:request","fetch:error","history:popstate","link:click","link:self","link:anchor","link:newtab","page:load","page:view","scroll:top","scroll:anchor","visit:start","visit:end"],this.swup=t,this.init()}init(){this.hooks.forEach(t=>this.create(t))}create(t){this.registry.has(t)||this.registry.set(t,new Map)}exists(t){return this.registry.has(t)}get(t){const e=this.registry.get(t);if(e)return e;console.error(`Unknown hook '${t}'`)}clear(){this.registry.forEach(t=>t.clear())}on(t,e,n){void 0===n&&(n={});const r=this.get(t);if(!r)return console.warn(`Hook '${t}' not found.`),()=>{};const o=r.size+1,i={...n,id:o,hook:t,handler:e};return r.set(e,i),()=>this.off(t,e)}before(t,e,n){return void 0===n&&(n={}),this.on(t,e,{...n,before:!0})}replace(t,e,n){return void 0===n&&(n={}),this.on(t,e,{...n,replace:!0})}once(t,e,n){return void 0===n&&(n={}),this.on(t,e,{...n,once:!0})}off(t,e){const n=this.get(t);n&&e?n.delete(e)||console.warn(`Handler for hook '${t}' not found.`):n&&n.clear()}call(t,e,n){try{const r=this,{before:o,handler:i,after:s}=r.getHandlers(t,n);return Promise.resolve(r.run(o,e)).then(function(){return Promise.resolve(r.run(i,e)).then(function(n){let[o]=n;return Promise.resolve(r.run(s,e)).then(function(){return r.dispatchDomEvent(t,e),o})})})}catch(t){return Promise.reject(t)}}callSync(t,e,n){const{before:r,handler:o,after:i}=this.getHandlers(t,n);this.runSync(r,e);const[s]=this.runSync(o,e);return this.runSync(i,e),this.dispatchDomEvent(t,e),s}run(t,e){try{const n=this,r=[],o=function(t,e,n){if("function"==typeof t[g]){var r,o,i,s=t[g]();if(function t(n){try{for(;!(r=s.next()).done;)if((n=e(r.value))&&n.then){if(!P(n))return void n.then(t,i||(i=w.bind(null,o=new y,2)));n=n.v}o?w(o,1,n):o=n}catch(t){w(o||(o=new y),2,t)}}(),s.return){var a=function(t){try{r.done||s.return()}catch(t){}return t};if(o&&o.then)return o.then(a,function(t){throw a(t)});a()}return o}if(!("length"in t))throw new TypeError("Object is not iterable");for(var c=[],l=0;l{const o=t(...e);d(o)?o.then(n,r):n(o)})}(i,[n.swup.visit,e,s])).then(function(t){r.push(t),a&&n.off(o,i)})});return Promise.resolve(o&&o.then?o.then(function(){return r}):r)}catch(t){return Promise.reject(t)}}runSync(t,e){const n=[];for(const{hook:r,handler:o,defaultHandler:i,once:s}of t){const t=o(this.swup.visit,e,i);n.push(t),d(t)&&console.warn(`Promise returned from handler for synchronous hook '${r}'.Swup will not wait for it to resolve.`),s&&this.off(r,o)}return n}getHandlers(t,e){const n=this.get(t);if(!n)return{found:!1,before:[],handler:[],after:[],replaced:!1};const r=Array.from(n.values()),o=this.sortRegistrations,i=r.filter(t=>{let{before:e,replace:n}=t;return e&&!n}).sort(o),s=r.filter(t=>{let{replace:e}=t;return e}).filter(t=>!0).sort(o),a=r.filter(t=>{let{before:e,replace:n}=t;return!e&&!n}).sort(o),c=s.length>0;let l=[];if(e&&(l=[{id:0,hook:t,handler:e}],c)){const n=s.length-1,r=t=>{const n=s[t-1];return n?(e,o)=>n.handler(e,o,r(t-1)):e};l=[{id:0,hook:t,handler:s[n].handler,defaultHandler:r(n)}]}return{found:!0,before:i,handler:l,after:a,replaced:c}}sortRegistrations(t,e){return(t.priority??0)-(e.priority??0)||t.id-e.id||0}dispatchDomEvent(t,e){document.dispatchEvent(new CustomEvent(`swup:${t}`,{detail:{hook:t,args:e,visit:this.swup.visit}}))}}const S=t=>{if(t&&"#"===t.charAt(0)&&(t=t.substring(1)),!t)return null;const e=decodeURIComponent(t);let n=document.getElementById(t)||document.getElementById(e)||l(`a[name='${m(t)}']`)||l(`a[name='${m(e)}']`);return n||"top"!==t||(n=document.body),n},b=function(t){let{elements:e,selector:n}=t;try{if(!1===n&&!e)return Promise.resolve();let t=[];if(e)t=Array.from(e);else if(n&&(t=h(n,document.body),!t.length))return console.warn(`[swup] No elements found matching animationSelector \`${n}\``),Promise.resolve();const r=t.map(t=>function(t){const{type:e,timeout:n,propCount:r}=function(t,e){const n=window.getComputedStyle(t),r=x(n,`${E}Delay`),o=x(n,`${E}Duration`),i=C(r,o),s=x(n,`${U}Delay`),a=x(n,`${U}Duration`),c=C(s,a);let l=null,h=0,u=0;return e===E?i>0&&(l=E,h=i,u=o.length):e===U?c>0&&(l=U,h=c,u=a.length):(h=Math.max(i,c),l=h>0?i>c?E:U:null,u=l?l===E?o.length:a.length:0),{type:l,timeout:h,propCount:u}}(t);return!(!e||!n)&&new Promise(o=>{const i=`${e}end`,s=performance.now();let a=0;const c=()=>{t.removeEventListener(i,l),o()},l=e=>{if(e.target===t){if(!function(t){return[`${E}end`,`${U}end`].includes(t.type)}(e))throw new Error("Not a transition or animation event.");(performance.now()-s)/1e3=r&&c()}};setTimeout(()=>{a0?Promise.resolve(Promise.all(r)).then(function(){}):(n&&console.warn(`[swup] No CSS animation duration defined on elements matching \`${n}\``),Promise.resolve())}catch(t){return Promise.reject(t)}},E="transition",U="animation";function x(t,e){return(t[e]||"").split(", ")}function C(t,e){for(;t.lengthf(e)+f(t[n])))}const $=function(t){void 0===t&&(t={});try{const o=this,i=o.visit,{el:s}=i.trigger;t.referrer=t.referrer||o.currentPageUrl,!1===t.animate&&(i.animation.animate=!1),i.animation.animate||o.classes.clear();const a=t.history||s?.getAttribute("data-swup-history")||void 0;a&&["push","replace"].includes(a)&&(i.history.action=a);const c=t.animation||s?.getAttribute("data-swup-animation")||void 0;return c&&(i.animation.name=c),"object"==typeof t.cache?(i.cache.read=t.cache.read??i.cache.read,i.cache.write=t.cache.write??i.cache.write):void 0!==t.cache&&(i.cache={read:!!t.cache,write:!!t.cache}),delete t.cache,Promise.resolve(function(s,a){try{var c=Promise.resolve(o.hooks.call("visit:start",void 0)).then(function(){function s(){const t=o.animatePageOut();return Promise.resolve(Promise.all([a,t])).then(function(t){let[e]=t;if(i.id===o.visit.id)return Promise.resolve(o.renderPage(e)).then(function(){return Promise.resolve(o.animatePageIn()).then(function(){return Promise.resolve(o.hooks.call("visit:end",void 0,()=>o.classes.clear())).then(function(){})})})})}const a=o.hooks.call("page:load",{options:t},function(t,e){try{function n(t){return e.page=t,e.cache=!!r,e.page}let r;return t.cache.read&&(r=o.cache.get(t.to.url)),Promise.resolve(r?n(r):Promise.resolve(o.fetchPage(t.to.url,e.options)).then(n))}catch(i){return Promise.reject(i)}});if(!i.history.popstate){const t=i.to.url+i.to.hash;"replace"===i.history.action||i.to.url===o.currentPageUrl?r(t):(o.currentHistoryIndex++,n(t,{index:o.currentHistoryIndex}))}o.currentPageUrl=e();const c=function(){if(i.animation.wait)return Promise.resolve(a).then(function(t){let{html:e}=t;i.to.html=e})}();return c&&c.then?c.then(s):s()})}catch(t){return a(t)}return c&&c.then?c.then(void 0,a):c}(0,function(t){t&&(console.error(t),o.options.skipPopStateHandling=()=>(window.location.href=i.to.url+i.to.hash,!0),window.history.go(-1))}))}catch(t){return Promise.reject(t)}};function H(t,e,n){if(void 0===e&&(e={}),void 0===n&&(n={}),"string"!=typeof t)throw new Error("swup.navigate() requires a URL parameter");if(this.shouldIgnoreVisit(t,{el:n.el,event:n.event}))return void(window.location.href=t);const{url:r,hash:o}=a.fromUrl(t);this.visit=this.createVisit({...n,to:r,hash:o}),this.performNavigation(e)}const A=function(t,e){void 0===e&&(e={});try{const n=this;t=a.fromUrl(t).url;const r={...n.options.requestHeaders,...e.headers};return e={...e,headers:r},Promise.resolve(n.hooks.call("fetch:request",{url:t,options:e},(t,e)=>{let{url:n,options:r}=e;return fetch(n,r)})).then(function(r){const{status:o,url:i}=r;return Promise.resolve(r.text()).then(function(s){if(500===o)throw n.hooks.call("fetch:error",{status:o,response:r,url:i}),new j(`Server error: ${i}`,{status:o,url:i});if(!s)throw new j(`Empty response: ${i}`,{status:o,url:i});const{url:c}=a.fromUrl(i),l={url:c,html:s};return!n.visit.cache.write||e.method&&"GET"!==e.method||t!==c||n.cache.set(l.url,l),l})})}catch(t){return Promise.reject(t)}};class j extends Error{constructor(t,e){super(t),this.url=void 0,this.status=void 0,this.name="FetchError",this.url=e.url,this.status=e.status}}const L=function(){try{let n;const r=this;function e(e){return n?e:Promise.resolve(r.hooks.call("animation:out:start",void 0,e=>{r.classes.add("is-changing","is-leaving","is-animating"),e.history.popstate&&r.classes.add("is-popstate"),e.animation.name&&r.classes.add(`to-${t(e.animation.name)}`)})).then(function(){return Promise.resolve(r.hooks.call("animation:out:await",{skip:!1},function(t,e){let{skip:n}=e;try{return n?Promise.resolve():Promise.resolve(r.awaitAnimations({selector:t.animation.selector})).then(function(){})}catch(t){return Promise.reject(t)}})).then(function(){return Promise.resolve(r.hooks.call("animation:out:end",void 0)).then(function(){})})})}const o=function(){if(!r.visit.animation.animate)return Promise.resolve(r.hooks.call("animation:skip",void 0)).then(function(){n=1})}();return Promise.resolve(o&&o.then?o.then(e):e(o))}catch(i){return Promise.reject(i)}},T=function(t,e){let{html:n}=t,{containers:r}=void 0===e?this.options:e;const o=(new DOMParser).parseFromString(n,"text/html"),i=o.querySelector("title")?.innerText||"";document.title=i;const s=h('[data-swup-persist]:not([data-swup-persist=""])'),a=r.map(t=>{const e=document.querySelector(t),n=o.querySelector(t);return e&&n?(e.replaceWith(n),!0):(e||console.warn(`[swup] Container missing in current document: ${t}`),n||console.warn(`[swup] Container missing in incoming document: ${t}`),!1)}).filter(Boolean);return s.forEach(t=>{const e=t.getAttribute("data-swup-persist"),n=l(`[data-swup-persist="${e}"]`);n&&n!==t&&n.replaceWith(t)}),a.length===r.length},I=function(){const t={behavior:"auto"},{target:e,reset:n}=this.visit.scroll,r=e??this.visit.to.hash;let o=!1;return r&&(o=this.hooks.callSync("scroll:anchor",{hash:r,options:t},(t,e)=>{let{hash:n,options:r}=e;const o=this.getAnchorElement(n);return o&&o.scrollIntoView(r),!!o})),n&&!o&&(o=this.hooks.callSync("scroll:top",{options:t},(t,e)=>{let{options:n}=e;return window.scrollTo({top:0,left:0,...n}),!0})),o},q=function(){try{const t=this;if(!t.visit.animation.animate)return Promise.resolve();const e=t.hooks.call("animation:in:await",{skip:!1},function(e,n){let{skip:r}=n;try{return r?Promise.resolve():Promise.resolve(t.awaitAnimations({selector:e.animation.selector})).then(function(){})}catch(t){return Promise.reject(t)}});return Promise.resolve(u()).then(function(){return Promise.resolve(t.hooks.call("animation:in:start",void 0,()=>{t.classes.remove("is-animating")})).then(function(){return Promise.resolve(e).then(function(){return Promise.resolve(t.hooks.call("animation:in:end",void 0)).then(function(){})})})})}catch(t){return Promise.reject(t)}},R=function(n){try{const o=this,{url:i,html:s}=n;return o.classes.remove("is-leaving"),o.isSameResolvedUrl(e(),i)||(r(i),o.currentPageUrl=e(),o.visit.to.url=o.currentPageUrl),o.visit.animation.animate&&o.classes.add("is-rendering"),o.visit.to.html=s,Promise.resolve(o.hooks.call("content:replace",{page:n},(e,n)=>{let{page:r}=n;if(!o.replaceContent(r,{containers:e.containers}))throw new Error("[swup] Container mismatch, aborting");e.animation.animate&&(o.classes.add("is-animating","is-changing","is-rendering"),e.animation.name&&o.classes.add(`to-${t(e.animation.name)}`))})).then(function(){return Promise.resolve(o.hooks.call("content:scroll",void 0,()=>o.scrollToContent())).then(function(){return Promise.resolve(o.hooks.call("page:view",{url:o.currentPageUrl,title:document.title})).then(function(){})})})}catch(t){return Promise.reject(t)}},N=function(t){var e;if(e=t,Boolean(e?.isSwupPlugin)){if(t.swup=this,!t._checkRequirements||t._checkRequirements())return t._beforeMount&&t._beforeMount(),t.mount(),this.plugins.push(t),this.plugins}else console.error("Not a swup plugin instance",t)};function M(t){const e=this.findPlugin(t);if(e)return e.unmount(),e._afterUnmount&&e._afterUnmount(),this.plugins=this.plugins.filter(t=>t!==e),this.plugins;console.error("No such plugin",e)}function D(t){return this.plugins.find(e=>e===t||e.name===t||e.name===`Swup${String(t)}`)}function W(t){if("function"!=typeof this.options.resolveUrl)return console.warn("[swup] options.resolveUrl expects a callback function."),t;const e=this.options.resolveUrl(t);return e&&"string"==typeof e?e.startsWith("//")||e.startsWith("http")?(console.warn("[swup] options.resolveUrl needs to return a relative url"),t):e:(console.warn("[swup] options.resolveUrl needs to return a url"),t)}function V(t,e){return this.resolveUrl(t)===this.resolveUrl(e)}const B={animateHistoryBrowsing:!1,animationSelector:'[class*="transition-"]',animationScope:"html",cache:!0,containers:["#swup"],ignoreVisit:function(t,e){let{el:n}=void 0===e?{}:e;return!!n?.closest("[data-no-swup]")},linkSelector:"a[href]",linkToSelf:"scroll",plugins:[],resolveUrl:t=>t,requestHeaders:{"X-Requested-With":"swup",Accept:"text/html, application/xhtml+xml"},skipPopStateHandling:t=>"swup"!==t.state?.source};return class{constructor(t){void 0===t&&(t={}),this.version="4.3.4",this.options=void 0,this.defaults=B,this.plugins=[],this.visit=void 0,this.cache=void 0,this.hooks=void 0,this.classes=void 0,this.currentPageUrl=e(),this.currentHistoryIndex=void 0,this.clickDelegate=void 0,this.use=N,this.unuse=M,this.findPlugin=D,this.log=()=>{},this.navigate=H,this.performNavigation=$,this.createVisit=v,this.delegateEvent=s,this.fetchPage=A,this.awaitAnimations=b,this.renderPage=R,this.replaceContent=T,this.animatePageIn=q,this.animatePageOut=L,this.scrollToContent=I,this.getAnchorElement=S,this.getCurrentUrl=e,this.resolveUrl=W,this.isSameResolvedUrl=V,this.options={...this.defaults,...t},this.handleLinkClick=this.handleLinkClick.bind(this),this.handlePopState=this.handlePopState.bind(this),this.cache=new c(this),this.classes=new p(this),this.hooks=new k(this),this.visit=this.createVisit({to:""}),this.currentHistoryIndex=history.state?.index??1,this.checkRequirements()&&this.enable()}checkRequirements(){return"undefined"!=typeof Promise||(console.warn("Promise is not supported"),!1)}enable(){try{const t=this,{linkSelector:e}=t.options;return t.clickDelegate=t.delegateEvent(e,"click",t.handleLinkClick),window.addEventListener("popstate",t.handlePopState),t.options.animateHistoryBrowsing&&(window.history.scrollRestoration="manual"),t.options.plugins.forEach(e=>t.use(e)),"swup"!==history.state?.source&&r(null,{index:t.currentHistoryIndex}),Promise.resolve(u()).then(function(){return Promise.resolve(t.hooks.call("enable",void 0,()=>{document.documentElement.classList.add("swup-enabled")})).then(function(){})})}catch(t){return Promise.reject(t)}}destroy(){try{const t=this;return t.clickDelegate.destroy(),window.removeEventListener("popstate",t.handlePopState),t.cache.clear(),t.options.plugins.forEach(e=>t.unuse(e)),Promise.resolve(t.hooks.call("disable",void 0,()=>{document.documentElement.classList.remove("swup-enabled")})).then(function(){t.hooks.clear()})}catch(t){return Promise.reject(t)}}shouldIgnoreVisit(t,e){let{el:n,event:r}=void 0===e?{}:e;const{origin:o,url:i,hash:s}=a.fromUrl(t);return o!==window.location.origin||!(!n||!this.triggerWillOpenNewWindow(n))||!!this.options.ignoreVisit(i+s,{el:n,event:r})}handleLinkClick(t){const e=t.delegateTarget,{href:n,url:o,hash:i}=a.fromElement(e);this.shouldIgnoreVisit(n,{el:e,event:t})||(this.visit=this.createVisit({to:o,hash:i,el:e,event:t}),t.metaKey||t.ctrlKey||t.shiftKey||t.altKey?this.hooks.call("link:newtab",{href:n}):0===t.button&&this.hooks.callSync("link:click",{el:e,event:t},()=>{const e=this.visit.from.url??"";t.preventDefault(),o&&o!==e?this.isSameResolvedUrl(o,e)||this.performNavigation():i?this.hooks.callSync("link:anchor",{hash:i},()=>{r(o+i),this.scrollToContent()}):this.hooks.callSync("link:self",void 0,()=>"navigate"===this.options.linkToSelf?this.performNavigation():(r(o),this.scrollToContent()))}))}handlePopState(t){const n=t.state?.url??location.href;if(this.options.skipPopStateHandling(t))return;if(this.isSameResolvedUrl(e(),this.currentPageUrl))return;const{url:r,hash:o}=a.fromUrl(n);this.visit=this.createVisit({to:r,hash:o,event:t}),this.visit.history.popstate=!0;const i=t.state?.index??0;i&&i!==this.currentHistoryIndex&&(this.visit.history.direction=i-this.currentHistoryIndex>0?"forwards":"backwards",this.currentHistoryIndex=i),this.visit.animation.animate=!1,this.visit.scroll.reset=!1,this.visit.scroll.target=!1,this.options.animateHistoryBrowsing&&(this.visit.animation.animate=!0,this.visit.scroll.reset=!0),this.hooks.callSync("history:popstate",{event:t},()=>{this.performNavigation()})}triggerWillOpenNewWindow(t){return!!t.matches('[download], [target="_blank"]')}}}); //# sourceMappingURL=Swup.umd.js.map diff --git a/assets/ts/modules/swupFadeTheme.js b/assets/ts/modules/swupFadeTheme.js index e270be42..6a270d12 100644 --- a/assets/ts/modules/swupFadeTheme.js +++ b/assets/ts/modules/swupFadeTheme.js @@ -1,408 +1,2 @@ -(function webpackUniversalModuleDefinition(root, factory) { - if(typeof exports === 'object' && typeof module === 'object') - module.exports = factory(); - else if(typeof define === 'function' && define.amd) - define([], factory); - else if(typeof exports === 'object') - exports["SwupFadeTheme"] = factory(); - else - root["SwupFadeTheme"] = factory(); -})(window, function() { -return /******/ (function(modules) { // webpackBootstrap -/******/ // The module cache -/******/ var installedModules = {}; -/******/ -/******/ // The require function -/******/ function __webpack_require__(moduleId) { -/******/ -/******/ // Check if module is in cache -/******/ if(installedModules[moduleId]) { -/******/ return installedModules[moduleId].exports; -/******/ } -/******/ // Create a new module (and put it into the cache) -/******/ var module = installedModules[moduleId] = { -/******/ i: moduleId, -/******/ l: false, -/******/ exports: {} -/******/ }; -/******/ -/******/ // Execute the module function -/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__); -/******/ -/******/ // Flag the module as loaded -/******/ module.l = true; -/******/ -/******/ // Return the exports of the module -/******/ return module.exports; -/******/ } -/******/ -/******/ -/******/ // expose the modules object (__webpack_modules__) -/******/ __webpack_require__.m = modules; -/******/ -/******/ // expose the module cache -/******/ __webpack_require__.c = installedModules; -/******/ -/******/ // define getter function for harmony exports -/******/ __webpack_require__.d = function(exports, name, getter) { -/******/ if(!__webpack_require__.o(exports, name)) { -/******/ Object.defineProperty(exports, name, { enumerable: true, get: getter }); -/******/ } -/******/ }; -/******/ -/******/ // define __esModule on exports -/******/ __webpack_require__.r = function(exports) { -/******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { -/******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); -/******/ } -/******/ Object.defineProperty(exports, '__esModule', { value: true }); -/******/ }; -/******/ -/******/ // create a fake namespace object -/******/ // mode & 1: value is a module id, require it -/******/ // mode & 2: merge all properties of value into the ns -/******/ // mode & 4: return value when already ns object -/******/ // mode & 8|1: behave like require -/******/ __webpack_require__.t = function(value, mode) { -/******/ if(mode & 1) value = __webpack_require__(value); -/******/ if(mode & 8) return value; -/******/ if((mode & 4) && typeof value === 'object' && value && value.__esModule) return value; -/******/ var ns = Object.create(null); -/******/ __webpack_require__.r(ns); -/******/ Object.defineProperty(ns, 'default', { enumerable: true, value: value }); -/******/ if(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key)); -/******/ return ns; -/******/ }; -/******/ -/******/ // getDefaultExport function for compatibility with non-harmony modules -/******/ __webpack_require__.n = function(module) { -/******/ var getter = module && module.__esModule ? -/******/ function getDefault() { return module['default']; } : -/******/ function getModuleExports() { return module; }; -/******/ __webpack_require__.d(getter, 'a', getter); -/******/ return getter; -/******/ }; -/******/ -/******/ // Object.prototype.hasOwnProperty.call -/******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); }; -/******/ -/******/ // __webpack_public_path__ -/******/ __webpack_require__.p = ""; -/******/ -/******/ -/******/ // Load entry module and return exports -/******/ return __webpack_require__(__webpack_require__.s = 0); -/******/ }) -/************************************************************************/ -/******/ ([ -/* 0 */ -/***/ (function(module, exports, __webpack_require__) { - -"use strict"; - - -var _index = __webpack_require__(1); - -var _index2 = _interopRequireDefault(_index); - -function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } - -module.exports = _index2.default; // this is here for webpack to expose SwupTheme as window.SwupTheme - -/***/ }), -/* 1 */ -/***/ (function(module, exports, __webpack_require__) { - -"use strict"; - - -Object.defineProperty(exports, "__esModule", { - value: true -}); - -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; }; - -var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); - -var _theme = __webpack_require__(2); - -var _theme2 = _interopRequireDefault(_theme); - -var _index = __webpack_require__(3); - -var _index2 = _interopRequireDefault(_index); - -function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } - -function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } - -function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; } - -function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } - -var FadeTheme = function (_Theme) { - _inherits(FadeTheme, _Theme); - - function FadeTheme(options) { - _classCallCheck(this, FadeTheme); - - var _this = _possibleConstructorReturn(this, (FadeTheme.__proto__ || Object.getPrototypeOf(FadeTheme)).call(this)); - - _this.name = 'FadeTheme'; - - - var defaultOptions = { - mainElement: '#swup' - }; - - _this.options = _extends({}, defaultOptions, options); - return _this; - } - - _createClass(FadeTheme, [{ - key: 'mount', - value: function mount() { - this.applyStyles(_index2.default); - this.addClassName(this.options.mainElement, 'main'); - } - }]); - - return FadeTheme; -}(_theme2.default); - -exports.default = FadeTheme; - -/***/ }), -/* 2 */ -/***/ (function(module, exports, __webpack_require__) { - -"use strict"; - - -Object.defineProperty(exports, "__esModule", { - value: true -}); - -var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); - -function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } - -var Theme = function () { - function Theme() { - var _this = this; - - _classCallCheck(this, Theme); - - this._addedStyleElements = []; - this._addedHTMLContent = []; - this._classNameAddedToElements = []; - - this._addClassNameToElement = function () { - _this._classNameAddedToElements.forEach(function (item) { - var elements = Array.prototype.slice.call(document.querySelectorAll(item.selector)); - elements.forEach(function (element) { - element.classList.add('swup-transition-' + item.name); - }); - }); - }; - - this.isSwupPlugin = true; - } - - _createClass(Theme, [{ - key: '_beforeMount', - value: function _beforeMount() { - // save original and replace animationSelector option - this._originalAnimationSelectorOption = String(this.swup.options.animationSelector); - this.swup.options.animationSelector = '[class*="swup-transition-"]'; - - // add classes after each content replace - this.swup.on('contentReplaced', this._addClassNameToElement); - } - }, { - key: '_afterUnmount', - value: function _afterUnmount() { - // reset animationSelector option - this.swup.options.animationSelector = this._originalAnimationSelectorOption; - - // remove added styles - this._addedStyleElements.forEach(function (element) { - element.outerHTML = ''; - element = null; - }); - - // remove added HTML - this._addedHTMLContent.forEach(function (element) { - element.outerHTML = ''; - element = null; - }); - - // remove added classnames - this._classNameAddedToElements.forEach(function (item) { - var elements = Array.prototype.slice.call(document.querySelectorAll(item.selector)); - elements.forEach(function (element) { - element.className.split(' ').forEach(function (classItem) { - if (new RegExp('^swup-transition-').test(classItem)) { - element.classList.remove(classItem); - } - }); - }); - }); - - this.swup.off('contentReplaced', this._addClassNameToElement); - } - }, { - key: 'mount', - value: function mount() { - // this is mount method rewritten by class extending - // and is executed when swup is enabled with theme - } - }, { - key: 'unmount', - value: function unmount() { - // this is unmount method rewritten by class extending - // and is executed when swup with theme is disabled - } - }, { - key: 'applyStyles', - value: function applyStyles(styles) { - var head = document.head; - var style = document.createElement('style'); - - style.setAttribute('data-swup-theme', ''); - style.appendChild(document.createTextNode(styles)); - - this._addedStyleElements.push(style); - head.prepend(style); - } - }, { - key: 'applyHTML', - value: function applyHTML(content) { - var element = document.createElement('div'); - element.innerHTML = content; - this._addedHTMLContent.push(element); - document.body.appendChild(element); - } - }, { - key: 'addClassName', - value: function addClassName(selector, name) { - // save so it can be later removed - this._classNameAddedToElements.push({ selector: selector, name: name }); - - // add class the first time - this._addClassNameToElement(); - } - - // this is here so we can tell if plugin was created by extending this class - - }]); - - return Theme; -}(); - -exports.default = Theme; - -/***/ }), -/* 3 */ -/***/ (function(module, exports, __webpack_require__) { - -exports = module.exports = __webpack_require__(4)(false); -// Module -exports.push([module.i, ".swup-transition-main {\n opacity: 1;\n transition: opacity .4s;\n}\n\nhtml.is-animating .swup-transition-main {\n opacity: 0;\n}", ""]); - - - -/***/ }), -/* 4 */ -/***/ (function(module, exports, __webpack_require__) { - -"use strict"; - - -/* - MIT License http://www.opensource.org/licenses/mit-license.php - Author Tobias Koppers @sokra -*/ -// css base code, injected by the css-loader -module.exports = function (useSourceMap) { - var list = []; // return the list of modules as css string - - list.toString = function toString() { - return this.map(function (item) { - var content = cssWithMappingToString(item, useSourceMap); - - if (item[2]) { - return '@media ' + item[2] + '{' + content + '}'; - } else { - return content; - } - }).join(''); - }; // import a list of modules into the list - - - list.i = function (modules, mediaQuery) { - if (typeof modules === 'string') { - modules = [[null, modules, '']]; - } - - var alreadyImportedModules = {}; - - for (var i = 0; i < this.length; i++) { - var id = this[i][0]; - - if (id != null) { - alreadyImportedModules[id] = true; - } - } - - for (i = 0; i < modules.length; i++) { - var item = modules[i]; // skip already imported module - // this implementation is not 100% perfect for weird media query combinations - // when a module is imported multiple times with different media queries. - // I hope this will never occur (Hey this way we have smaller bundles) - - if (item[0] == null || !alreadyImportedModules[item[0]]) { - if (mediaQuery && !item[2]) { - item[2] = mediaQuery; - } else if (mediaQuery) { - item[2] = '(' + item[2] + ') and (' + mediaQuery + ')'; - } - - list.push(item); - } - } - }; - - return list; -}; - -function cssWithMappingToString(item, useSourceMap) { - var content = item[1] || ''; - var cssMapping = item[3]; - - if (!cssMapping) { - return content; - } - - if (useSourceMap && typeof btoa === 'function') { - var sourceMapping = toComment(cssMapping); - var sourceURLs = cssMapping.sources.map(function (source) { - return '/*# sourceURL=' + cssMapping.sourceRoot + source + ' */'; - }); - return [content].concat(sourceURLs).concat([sourceMapping]).join('\n'); - } - - return [content].join('\n'); -} // Adapted from convert-source-map (MIT) - - -function toComment(sourceMap) { - // eslint-disable-next-line no-undef - var base64 = btoa(unescape(encodeURIComponent(JSON.stringify(sourceMap)))); - var data = 'sourceMappingURL=data:application/json;charset=utf-8;base64,' + base64; - return '/*# ' + data + ' */'; -} - -/***/ }) -/******/ ]); -}); \ No newline at end of file +!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e||self).SwupFadeTheme=t()}(this,function(){function e(){return e=Object.assign?Object.assign.bind():function(e){for(var t=1;tString(e).split(".").map(e=>String(parseInt(e||"0",10))).concat(["0","0"]).slice(0,3).join(".");class n{constructor(){this.isSwupPlugin=!0,this.swup=void 0,this.version=void 0,this.requires={},this.handlersToUnregister=[]}mount(){}unmount(){this.handlersToUnregister.forEach(e=>e()),this.handlersToUnregister=[]}_beforeMount(){if(!this.name)throw new Error("You must define a name of plugin when creating a class.")}_afterUnmount(){}_checkRequirements(){return"object"!=typeof this.requires||Object.entries(this.requires).forEach(([e,n])=>{if(!function(e,n,s){const o=function(e,t){var n;if("swup"===e)return null!=(n=t.version)?n:"";{var s;const n=t.findPlugin(e);return null!=(s=null==n?void 0:n.version)?s:""}}(e,s);return!!o&&((e,n)=>n.every(n=>{const[,s,o]=n.match(/^([\D]+)?(.*)$/)||[];var i,r;return((e,t)=>{const n={"":e=>0===e,">":e=>e>0,">=":e=>e>=0,"<":e=>e<0,"<=":e=>e<=0};return(n[t]||n[""])(e)})((r=o,i=t(i=e),r=t(r),i.localeCompare(r,void 0,{numeric:!0})),s||">=")}))(o,n)}(e,n=Array.isArray(n)?n:[n],this.swup)){const t=`${e} ${n.join(", ")}`;throw new Error(`Plugin version mismatch: ${this.name} requires ${t}`)}}),!0}on(e,t,n={}){var s;t=!(s=t).name.startsWith("bound ")||s.hasOwnProperty("prototype")?t.bind(this):t;const o=this.swup.hooks.on(e,t,n);return this.handlersToUnregister.push(o),o}once(t,n,s={}){return this.on(t,n,e({},s,{once:!0}))}before(t,n,s={}){return this.on(t,n,e({},s,{before:!0}))}replace(t,n,s={}){return this.on(t,n,e({},s,{replace:!0}))}off(e,t){return this.swup.hooks.off(e,t)}}class s extends n{constructor(...e){super(...e),this._addedStyleElements=[],this._addedHTMLContent=[],this._classNameAddedToElements=[],this._addClassNameToElement=()=>{this._classNameAddedToElements.forEach(e=>{Array.from(document.querySelectorAll(e.selector)).forEach(t=>{t.classList.add(`swup-transition-${e.name}`)})})}}_beforeMount(){this._originalAnimationSelectorOption=String(this.swup.options.animationSelector),this.swup.options.animationSelector='[class*="swup-transition-"]',this.swup.hooks.on("content:replace",this._addClassNameToElement)}_afterUnmount(){this.swup.options.animationSelector=this._originalAnimationSelectorOption,this._addedStyleElements.forEach(e=>{e.outerHTML="",e=null}),this._addedHTMLContent.forEach(e=>{e.outerHTML="",e=null}),this._classNameAddedToElements.forEach(e=>{Array.from(document.querySelectorAll(e.selector)).forEach(e=>{e.className.split(" ").forEach(t=>{new RegExp("^swup-transition-").test(t)&&e.classList.remove(t)})})}),this.swup.hooks.off("content:replace",this._addClassNameToElement)}applyStyles(e){const t=document.createElement("style");t.setAttribute("data-swup-theme",""),t.appendChild(document.createTextNode(e)),document.head.prepend(t),this._addedStyleElements.push(t)}applyHTML(e){const t=document.createElement("div");t.innerHTML=e,document.body.appendChild(t),this._addedHTMLContent.push(t)}addClassName(e,t){this._classNameAddedToElements.push({selector:e,name:t}),this._addClassNameToElement()}}return class extends s{constructor(e){void 0===e&&(e={}),super(),this.name="SwupFadeTheme",this.defaults={mainElement:"#swup"},this.options={...this.defaults,...e}}mount(){this.applyStyles("html{--swup-fade-theme-duration:.4s}html.is-changing .swup-transition-main{opacity:1;transition:opacity var(--swup-fade-theme-duration)}html.is-animating .swup-transition-main{opacity:0}"),this.addClassName(this.options.mainElement,"main")}}}); +//# sourceMappingURL=index.umd.js.map diff --git a/assets/ts/modules/swupGaPlugin.js b/assets/ts/modules/swupGaPlugin.js index ac2c2bfa..ca2cdb76 100644 --- a/assets/ts/modules/swupGaPlugin.js +++ b/assets/ts/modules/swupGaPlugin.js @@ -1,244 +1,2 @@ -(function webpackUniversalModuleDefinition(root, factory) { - if(typeof exports === 'object' && typeof module === 'object') - module.exports = factory(); - else if(typeof define === 'function' && define.amd) - define([], factory); - else if(typeof exports === 'object') - exports["SwupGaPlugin"] = factory(); - else - root["SwupGaPlugin"] = factory(); -})(window, function() { -return /******/ (function(modules) { // webpackBootstrap -/******/ // The module cache -/******/ var installedModules = {}; -/******/ -/******/ // The require function -/******/ function __webpack_require__(moduleId) { -/******/ -/******/ // Check if module is in cache -/******/ if(installedModules[moduleId]) { -/******/ return installedModules[moduleId].exports; -/******/ } -/******/ // Create a new module (and put it into the cache) -/******/ var module = installedModules[moduleId] = { -/******/ i: moduleId, -/******/ l: false, -/******/ exports: {} -/******/ }; -/******/ -/******/ // Execute the module function -/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__); -/******/ -/******/ // Flag the module as loaded -/******/ module.l = true; -/******/ -/******/ // Return the exports of the module -/******/ return module.exports; -/******/ } -/******/ -/******/ -/******/ // expose the modules object (__webpack_modules__) -/******/ __webpack_require__.m = modules; -/******/ -/******/ // expose the module cache -/******/ __webpack_require__.c = installedModules; -/******/ -/******/ // define getter function for harmony exports -/******/ __webpack_require__.d = function(exports, name, getter) { -/******/ if(!__webpack_require__.o(exports, name)) { -/******/ Object.defineProperty(exports, name, { enumerable: true, get: getter }); -/******/ } -/******/ }; -/******/ -/******/ // define __esModule on exports -/******/ __webpack_require__.r = function(exports) { -/******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { -/******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); -/******/ } -/******/ Object.defineProperty(exports, '__esModule', { value: true }); -/******/ }; -/******/ -/******/ // create a fake namespace object -/******/ // mode & 1: value is a module id, require it -/******/ // mode & 2: merge all properties of value into the ns -/******/ // mode & 4: return value when already ns object -/******/ // mode & 8|1: behave like require -/******/ __webpack_require__.t = function(value, mode) { -/******/ if(mode & 1) value = __webpack_require__(value); -/******/ if(mode & 8) return value; -/******/ if((mode & 4) && typeof value === 'object' && value && value.__esModule) return value; -/******/ var ns = Object.create(null); -/******/ __webpack_require__.r(ns); -/******/ Object.defineProperty(ns, 'default', { enumerable: true, value: value }); -/******/ if(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key)); -/******/ return ns; -/******/ }; -/******/ -/******/ // getDefaultExport function for compatibility with non-harmony modules -/******/ __webpack_require__.n = function(module) { -/******/ var getter = module && module.__esModule ? -/******/ function getDefault() { return module['default']; } : -/******/ function getModuleExports() { return module; }; -/******/ __webpack_require__.d(getter, 'a', getter); -/******/ return getter; -/******/ }; -/******/ -/******/ // Object.prototype.hasOwnProperty.call -/******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); }; -/******/ -/******/ // __webpack_public_path__ -/******/ __webpack_require__.p = ""; -/******/ -/******/ -/******/ // Load entry module and return exports -/******/ return __webpack_require__(__webpack_require__.s = 0); -/******/ }) -/************************************************************************/ -/******/ ([ -/* 0 */ -/***/ (function(module, exports, __webpack_require__) { - -"use strict"; - - -var _index = __webpack_require__(1); - -var _index2 = _interopRequireDefault(_index); - -function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } - -module.exports = _index2.default; // this is here for webpack to expose SwupPlugin as window.SwupPlugin - -/***/ }), -/* 1 */ -/***/ (function(module, exports, __webpack_require__) { - -"use strict"; - - -Object.defineProperty(exports, "__esModule", { - value: true -}); - -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; }; - -var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); - -var _plugin = __webpack_require__(2); - -var _plugin2 = _interopRequireDefault(_plugin); - -function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } - -function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } - -function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; } - -function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } - -var GaPlugin = function (_Plugin) { - _inherits(GaPlugin, _Plugin); - - function GaPlugin(options) { - _classCallCheck(this, GaPlugin); - - var _this = _possibleConstructorReturn(this, (GaPlugin.__proto__ || Object.getPrototypeOf(GaPlugin)).call(this)); - - _this.name = 'GaPlugin'; - - var defaultOptions = { - gaMeasurementId: null - }; - - _this.options = _extends({}, defaultOptions, options); - return _this; - } - - _createClass(GaPlugin, [{ - key: 'mount', - value: function mount() { - var _this2 = this; - - this.swup.on('contentReplaced', function (event) { - if (typeof gtag === 'function') { - var title = document.title; - var url = window.location.pathname + window.location.search; - var gaId = _this2.options.gaMeasurementId; - - if (!gaId) { - throw new Error('gaMeasurementId option is required for gtag.'); - } - - window.gtag('config', gaId, { - page_title: title, - page_path: url - }); - _this2.swup.log('GTAG pageview (url \'' + url + '\').'); - } else if (typeof window.ga === 'function') { - var _title = document.title; - var _url = window.location.pathname + window.location.search; - - window.ga('set', 'title', _title); - window.ga('set', 'page', _url); - window.ga('send', 'pageview'); - - _this2.swup.log('GA pageview (url \'' + _url + '\').'); - } else { - console.warn("window.gtag and window.ga don't exists."); - } - }); - } - }]); - - return GaPlugin; -}(_plugin2.default); - -exports.default = GaPlugin; - -/***/ }), -/* 2 */ -/***/ (function(module, exports, __webpack_require__) { - -"use strict"; - - -Object.defineProperty(exports, "__esModule", { - value: true -}); - -var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); - -function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } - -var Plugin = function () { - function Plugin() { - _classCallCheck(this, Plugin); - - this.isSwupPlugin = true; - } - - _createClass(Plugin, [{ - key: "mount", - value: function mount() { - // this is mount method rewritten by class extending - // and is executed when swup is enabled with plugin - } - }, { - key: "unmount", - value: function unmount() {} - // this is unmount method rewritten by class extending - // and is executed when swup with plugin is disabled - - - // this is here so we can tell if plugin was created by extending this class - - }]); - - return Plugin; -}(); - -exports.default = Plugin; - -/***/ }) -/******/ ]); -}); \ No newline at end of file +!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e||self).SwupGaPlugin=t()}(this,function(){function e(){return e=Object.assign?Object.assign.bind():function(e){for(var t=1;tString(e).split(".").map(e=>String(parseInt(e||"0",10))).concat(["0","0"]).slice(0,3).join(".");class n{constructor(){this.isSwupPlugin=!0,this.swup=void 0,this.version=void 0,this.requires={},this.handlersToUnregister=[]}mount(){}unmount(){this.handlersToUnregister.forEach(e=>e()),this.handlersToUnregister=[]}_beforeMount(){if(!this.name)throw new Error("You must define a name of plugin when creating a class.")}_afterUnmount(){}_checkRequirements(){return"object"!=typeof this.requires||Object.entries(this.requires).forEach(([e,n])=>{if(!function(e,n,i){const r=function(e,t){var n;if("swup"===e)return null!=(n=t.version)?n:"";{var i;const n=t.findPlugin(e);return null!=(i=null==n?void 0:n.version)?i:""}}(e,i);return!!r&&((e,n)=>n.every(n=>{const[,i,r]=n.match(/^([\D]+)?(.*)$/)||[];var o,s;return((e,t)=>{const n={"":e=>0===e,">":e=>e>0,">=":e=>e>=0,"<":e=>e<0,"<=":e=>e<=0};return(n[t]||n[""])(e)})((s=r,o=t(o=e),s=t(s),o.localeCompare(s,void 0,{numeric:!0})),i||">=")}))(r,n)}(e,n=Array.isArray(n)?n:[n],this.swup)){const t=`${e} ${n.join(", ")}`;throw new Error(`Plugin version mismatch: ${this.name} requires ${t}`)}}),!0}on(e,t,n={}){var i;t=!(i=t).name.startsWith("bound ")||i.hasOwnProperty("prototype")?t.bind(this):t;const r=this.swup.hooks.on(e,t,n);return this.handlersToUnregister.push(r),r}once(t,n,i={}){return this.on(t,n,e({},i,{once:!0}))}before(t,n,i={}){return this.on(t,n,e({},i,{before:!0}))}replace(t,n,i={}){return this.on(t,n,e({},i,{replace:!0}))}off(e,t){return this.swup.hooks.off(e,t)}}return class extends n{constructor(e){void 0===e&&(e={}),super(),this.name="SwupGaPlugin",this.requires={swup:">=4"},this.defaults={gaMeasurementId:null},this.options={...this.defaults,...e}}mount(){this.on("page:view",this.trackPageView)}trackPageView(){const e=document.title,t=window.location.pathname+window.location.search;"function"==typeof window.gtag?(this.trackPageViewInGtag({title:e,url:t}),this.swup.log(`GA page view: ${t} (gtag.js)`)):"function"==typeof window.ga?(this.trackPageViewInGa({title:e,url:t}),this.swup.log(`GA page view: ${t} (analytics.js)`)):console.warn("Neither window.gtag nor window.ga are present on the page")}trackPageViewInGtag(e){let{title:t,url:n}=e;const{gaMeasurementId:i}=this.options;i?window.gtag("config",i,{page_title:t,page_path:n}):console.error("The gaMeasurementId option is required for gtag.js")}trackPageViewInGa(e){let{title:t,url:n}=e;window.ga("set","title",t),window.ga("set","page",n),window.ga("send","pageview")}}}); +//# sourceMappingURL=index.umd.js.map diff --git a/assets/ts/modules/swupHeadPlugin.js b/assets/ts/modules/swupHeadPlugin.js index 48969300..33764d4d 100644 --- a/assets/ts/modules/swupHeadPlugin.js +++ b/assets/ts/modules/swupHeadPlugin.js @@ -1,519 +1,2 @@ -(function webpackUniversalModuleDefinition(root, factory) { - if(typeof exports === 'object' && typeof module === 'object') - module.exports = factory(); - else if(typeof define === 'function' && define.amd) - define([], factory); - else if(typeof exports === 'object') - exports["SwupHeadPlugin"] = factory(); - else - root["SwupHeadPlugin"] = factory(); -})(window, function() { -return /******/ (function(modules) { // webpackBootstrap -/******/ // The module cache -/******/ var installedModules = {}; -/******/ -/******/ // The require function -/******/ function __webpack_require__(moduleId) { -/******/ -/******/ // Check if module is in cache -/******/ if(installedModules[moduleId]) { -/******/ return installedModules[moduleId].exports; -/******/ } -/******/ // Create a new module (and put it into the cache) -/******/ var module = installedModules[moduleId] = { -/******/ i: moduleId, -/******/ l: false, -/******/ exports: {} -/******/ }; -/******/ -/******/ // Execute the module function -/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__); -/******/ -/******/ // Flag the module as loaded -/******/ module.l = true; -/******/ -/******/ // Return the exports of the module -/******/ return module.exports; -/******/ } -/******/ -/******/ -/******/ // expose the modules object (__webpack_modules__) -/******/ __webpack_require__.m = modules; -/******/ -/******/ // expose the module cache -/******/ __webpack_require__.c = installedModules; -/******/ -/******/ // define getter function for harmony exports -/******/ __webpack_require__.d = function(exports, name, getter) { -/******/ if(!__webpack_require__.o(exports, name)) { -/******/ Object.defineProperty(exports, name, { enumerable: true, get: getter }); -/******/ } -/******/ }; -/******/ -/******/ // define __esModule on exports -/******/ __webpack_require__.r = function(exports) { -/******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { -/******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); -/******/ } -/******/ Object.defineProperty(exports, '__esModule', { value: true }); -/******/ }; -/******/ -/******/ // create a fake namespace object -/******/ // mode & 1: value is a module id, require it -/******/ // mode & 2: merge all properties of value into the ns -/******/ // mode & 4: return value when already ns object -/******/ // mode & 8|1: behave like require -/******/ __webpack_require__.t = function(value, mode) { -/******/ if(mode & 1) value = __webpack_require__(value); -/******/ if(mode & 8) return value; -/******/ if((mode & 4) && typeof value === 'object' && value && value.__esModule) return value; -/******/ var ns = Object.create(null); -/******/ __webpack_require__.r(ns); -/******/ Object.defineProperty(ns, 'default', { enumerable: true, value: value }); -/******/ if(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key)); -/******/ return ns; -/******/ }; -/******/ -/******/ // getDefaultExport function for compatibility with non-harmony modules -/******/ __webpack_require__.n = function(module) { -/******/ var getter = module && module.__esModule ? -/******/ function getDefault() { return module['default']; } : -/******/ function getModuleExports() { return module; }; -/******/ __webpack_require__.d(getter, 'a', getter); -/******/ return getter; -/******/ }; -/******/ -/******/ // Object.prototype.hasOwnProperty.call -/******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); }; -/******/ -/******/ // __webpack_public_path__ -/******/ __webpack_require__.p = ""; -/******/ -/******/ -/******/ // Load entry module and return exports -/******/ return __webpack_require__(__webpack_require__.s = 0); -/******/ }) -/************************************************************************/ -/******/ ([ -/* 0 */ -/***/ (function(module, exports, __webpack_require__) { - -"use strict"; - - -var _index = __webpack_require__(1); - -var _index2 = _interopRequireDefault(_index); - -function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } - -module.exports = _index2.default; // this is here for webpack to expose SwupPlugin as window.SwupPlugin - -/***/ }), -/* 1 */ -/***/ (function(module, exports, __webpack_require__) { - -"use strict"; - - -Object.defineProperty(exports, "__esModule", { - value: true -}); - -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; }; - -var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); - -var _plugin = __webpack_require__(2); - -var _plugin2 = _interopRequireDefault(_plugin); - -var _mergeHeadContents2 = __webpack_require__(3); - -var _mergeHeadContents3 = _interopRequireDefault(_mergeHeadContents2); - -var _updateLangAttribute = __webpack_require__(4); - -var _updateLangAttribute2 = _interopRequireDefault(_updateLangAttribute); - -var _waitForAssets = __webpack_require__(5); - -var _waitForAssets2 = _interopRequireDefault(_waitForAssets); - -function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } - -function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } - -function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; } - -function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } - -var HeadPlugin = function (_Plugin) { - _inherits(HeadPlugin, _Plugin); - - function HeadPlugin() { - var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; - - _classCallCheck(this, HeadPlugin); - - var _this = _possibleConstructorReturn(this, (HeadPlugin.__proto__ || Object.getPrototypeOf(HeadPlugin)).call(this)); - - _this.name = 'HeadPlugin'; - _this.assetLoadPromises = []; - - _this.updateHead = function () { - var newPageHtml = _this.swup.cache.getCurrentPage().originalContent; - var newDocument = new DOMParser().parseFromString(newPageHtml, 'text/html'); - - var _mergeHeadContents = (0, _mergeHeadContents3.default)(document.head, newDocument.head, { shouldPersist: _this.isPersistentTag }), - removed = _mergeHeadContents.removed, - added = _mergeHeadContents.added; - - var lang = (0, _updateLangAttribute2.default)(document.documentElement, newDocument.documentElement); - - _this.swup.log('Removed ' + removed.length + ' / added ' + added.length + ' tags in head'); - if (lang) { - _this.swup.log('Updated lang attribute: ' + lang); - } - - if (_this.options.awaitAssets) { - _this.assetLoadPromises = (0, _waitForAssets2.default)(added, _this.options.timeout); - } else { - _this.assetLoadPromises = []; - } - - newDocument.documentElement.innerHTML = ''; - newDocument = null; - }; - - _this.isPersistentTag = function (el) { - var persistTags = _this.options.persistTags; - - if (typeof persistTags === 'function') { - return persistTags(el); - } - if (typeof persistTags === 'string') { - return el.matches(persistTags); - } - return Boolean(persistTags); - }; - - _this.options = _extends({ - persistTags: false, - persistAssets: false, - awaitAssets: false, - timeout: 3000 - }, options); - return _this; - } - - _createClass(HeadPlugin, [{ - key: 'mount', - value: function mount() { - this.validateOptions(); - - // Replace head contents right before content itself - this.swup.on('willReplaceContent', this.updateHead); - - // Overwrite swup's replaceContent to let us defer until all assets are loaded - if (this.options.awaitAssets) { - this.originalSwupReplaceContent = this.swup.replaceContent.bind(this.swup); - this.swup.replaceContent = this.replaceContentAfterAssetsLoaded.bind(this); - } - } - }, { - key: 'unmount', - value: function unmount() { - this.swup.off('willReplaceContent', this.updateHead); - - if (this.originalSwupReplaceContent) { - this.swup.replaceContent = this.originalSwupReplaceContent; - this.originalSwupReplaceContent = null; - } - } - }, { - key: 'validateOptions', - value: function validateOptions() { - // options.persistAssets is a shortcut for: - // options.persistTags with a default asset selector for scripts & styles - if (this.options.persistAssets && !this.options.persistTags) { - this.options.persistTags = 'link[rel=stylesheet], script[src], style'; - } - - // Make sure the swup version in use supports hooking into `replaceContent` - if (this.options.awaitAssets && !this.swup.replaceContent) { - this.options.awaitAssets = false; - console.error('[Swup Head Plugin] Installed version of swup doesn\'t support awaitAssets option'); - } - } - }, { - key: 'replaceContentAfterAssetsLoaded', - value: function replaceContentAfterAssetsLoaded() { - var _this2 = this; - - for (var _len = arguments.length, originalArgs = Array(_len), _key = 0; _key < _len; _key++) { - originalArgs[_key] = arguments[_key]; - } - - if (this.assetLoadPromises.length) { - this.swup.log('Waiting for ' + this.assetLoadPromises.length + ' assets to load'); - return new Promise(function (resolve) { - Promise.all(_this2.assetLoadPromises).then(function () { - _this2.assetLoadPromises = []; - _this2.originalSwupReplaceContent.apply(_this2, originalArgs).then(resolve); - }); - }); - } else { - return this.originalSwupReplaceContent.apply(this, originalArgs); - } - } - }]); - - return HeadPlugin; -}(_plugin2.default); - -exports.default = HeadPlugin; - -/***/ }), -/* 2 */ -/***/ (function(module, exports, __webpack_require__) { - -"use strict"; - - -Object.defineProperty(exports, "__esModule", { - value: true -}); - -var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); - -function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } - -var Plugin = function () { - function Plugin() { - _classCallCheck(this, Plugin); - - this.isSwupPlugin = true; - } - - _createClass(Plugin, [{ - key: "mount", - value: function mount() { - // this is mount method rewritten by class extending - // and is executed when swup is enabled with plugin - } - }, { - key: "unmount", - value: function unmount() { - // this is unmount method rewritten by class extending - // and is executed when swup with plugin is disabled - } - }, { - key: "_beforeMount", - value: function _beforeMount() { - // here for any future hidden auto init - } - }, { - key: "_afterUnmount", - value: function _afterUnmount() {} - // here for any future hidden auto-cleanup - - - // this is here so we can tell if plugin was created by extending this class - - }]); - - return Plugin; -}(); - -exports.default = Plugin; - -/***/ }), -/* 3 */ -/***/ (function(module, exports, __webpack_require__) { - -"use strict"; - - -Object.defineProperty(exports, "__esModule", { - value: true -}); -exports.default = mergeHeadContents; -function mergeHeadContents(currentHead, newHead) { - var _ref = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}, - _ref$shouldPersist = _ref.shouldPersist, - shouldPersist = _ref$shouldPersist === undefined ? function () { - return false; - } : _ref$shouldPersist; - - var themeActive = Boolean(document.querySelector('[data-swup-theme]')); - - var currentTags = Array.from(currentHead.children); - var newChildren = Array.from(newHead.children); - - var addTags = getTagsToAdd(currentTags, newChildren, { themeActive: themeActive }); - var removeTags = getTagsToRemove(currentTags, newChildren); - - // Remove tags in reverse to keep indexes, keep persistant elements - removeTags.reverse().filter(function (_ref2) { - var el = _ref2.el; - return shouldManageTag(el); - }).filter(function (_ref3) { - var el = _ref3.el; - return !shouldPersist(el); - }).forEach(function (_ref4) { - var el = _ref4.el; - return currentHead.removeChild(el); - }); - - // Insert tag *after* previous version of itself to preserve JS variable scope and CSS cascaade - addTags.filter(function (_ref5) { - var el = _ref5.el; - return shouldManageTag(el); - }).forEach(function (_ref6) { - var el = _ref6.el, - index = _ref6.index; - - currentHead.insertBefore(el, currentHead.children[index + 1] || null); - }); - - return { - removed: removeTags.map(function (_ref7) { - var el = _ref7.el; - return el; - }), - added: addTags.map(function (_ref8) { - var el = _ref8.el; - return el; - }) - }; -}; - -function getTagsToRemove(currentEls, newEls) { - return currentEls.reduce(function (tags, el) { - var isAmongNew = newEls.some(function (newEl) { - return compareTags(el, newEl); - }); - var isThemeTag = el.matches('[data-swup-theme]'); - if (!isAmongNew && !isThemeTag) { - tags.push({ el: el }); - } - return tags; - }, []); -}; - -function getTagsToAdd(currentEls, newEls, _ref9) { - var themeActive = _ref9.themeActive; - - return newEls.reduce(function (tags, el, i) { - var isAmongCurrent = currentEls.some(function (currentEl) { - return compareTags(el, currentEl); - }); - if (!isAmongCurrent) { - var index = themeActive ? i + 1 : i; - tags.push({ el: el, index: index }); - } - return tags; - }, []); -}; - -function shouldManageTag(el) { - return el.localName !== 'title'; // swup manages title itself -} - -function compareTags(oldTag, newTag) { - return oldTag.outerHTML === newTag.outerHTML; -} - -/***/ }), -/* 4 */ -/***/ (function(module, exports, __webpack_require__) { - -"use strict"; - - -Object.defineProperty(exports, "__esModule", { - value: true -}); -exports.default = updateLangAttribute; -function updateLangAttribute(currentHtml, newHtml) { - if (currentHtml.lang !== newHtml.lang) { - currentHtml.lang = newHtml.lang; - return currentHtml.lang; - } else { - return null; - } -}; - -/***/ }), -/* 5 */ -/***/ (function(module, exports, __webpack_require__) { - -"use strict"; - - -Object.defineProperty(exports, "__esModule", { - value: true -}); -exports.default = waitForAssets; - -var _waitForStylesheet = __webpack_require__(6); - -var _waitForStylesheet2 = _interopRequireDefault(_waitForStylesheet); - -function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } - -function waitForAssets(elements) { - var timeoutMs = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0; - - return elements.filter(function (el) { - return el.matches('link[rel=stylesheet][href]'); - }).map(function (el) { - return (0, _waitForStylesheet2.default)(el, timeoutMs); - }); -}; - -/***/ }), -/* 6 */ -/***/ (function(module, exports, __webpack_require__) { - -"use strict"; - - -Object.defineProperty(exports, "__esModule", { - value: true -}); -exports.default = waitForStylesheet; -function waitForStylesheet(element) { - var timeoutMs = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0; - - var isLoaded = function isLoaded(_ref) { - var href = _ref.href; - - return Array.from(document.styleSheets).map(function (_ref2) { - var href = _ref2.href; - return href; - }).includes(href); - }; - - var whenLoaded = function whenLoaded(cb) { - if (isLoaded(element)) { - cb(); - } else { - setTimeout(function () { - return whenLoaded(cb); - }, 10); - } - }; - - return new Promise(function (resolve) { - whenLoaded(resolve); - if (timeoutMs > 0) { - setTimeout(resolve, timeoutMs); - } - }); -}; - -/***/ }) -/******/ ]); -}); \ No newline at end of file +!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e||self).SwupHeadPlugin=t()}(this,function(){function e(){return e=Object.assign?Object.assign.bind():function(e){for(var t=1;tString(e).split(".").map(e=>String(parseInt(e||"0",10))).concat(["0","0"]).slice(0,3).join(".");class n{constructor(){this.isSwupPlugin=!0,this.swup=void 0,this.version=void 0,this.requires={},this.handlersToUnregister=[]}mount(){}unmount(){this.handlersToUnregister.forEach(e=>e()),this.handlersToUnregister=[]}_beforeMount(){if(!this.name)throw new Error("You must define a name of plugin when creating a class.")}_afterUnmount(){}_checkRequirements(){return"object"!=typeof this.requires||Object.entries(this.requires).forEach(([e,n])=>{if(!function(e,n,r){const s=function(e,t){var n;if("swup"===e)return null!=(n=t.version)?n:"";{var r;const n=t.findPlugin(e);return null!=(r=null==n?void 0:n.version)?r:""}}(e,r);return!!s&&((e,n)=>n.every(n=>{const[,r,s]=n.match(/^([\D]+)?(.*)$/)||[];var o,i;return((e,t)=>{const n={"":e=>0===e,">":e=>e>0,">=":e=>e>=0,"<":e=>e<0,"<=":e=>e<=0};return(n[t]||n[""])(e)})((i=s,o=t(o=e),i=t(i),o.localeCompare(i,void 0,{numeric:!0})),r||">=")}))(s,n)}(e,n=Array.isArray(n)?n:[n],this.swup)){const t=`${e} ${n.join(", ")}`;throw new Error(`Plugin version mismatch: ${this.name} requires ${t}`)}}),!0}on(e,t,n={}){var r;t=!(r=t).name.startsWith("bound ")||r.hasOwnProperty("prototype")?t.bind(this):t;const s=this.swup.hooks.on(e,t,n);return this.handlersToUnregister.push(s),s}once(t,n,r={}){return this.on(t,n,e({},r,{once:!0}))}before(t,n,r={}){return this.on(t,n,e({},r,{before:!0}))}replace(t,n,r={}){return this.on(t,n,e({},r,{replace:!0}))}off(e,t){return this.swup.hooks.off(e,t)}}function r(e){return"title"!==e.localName&&!e.matches("[data-swup-theme]")}function s(e,t){return e.outerHTML===t.outerHTML}function o(e){return e.matches("link[rel=stylesheet][href]")}return class extends n{constructor(e){void 0===e&&(e={}),super();const t=this;this.name="SwupHeadPlugin",this.requires={swup:">=4"},this.defaults={persistTags:!1,persistAssets:!1,awaitAssets:!1,timeout:3e3},this.options=void 0,this.updateHead=function(e,n){let{page:{html:i}}=n;try{const e=(new DOMParser).parseFromString(i,"text/html"),{removed:n,added:l}=function(e,t,n){let{shouldPersist:o=(()=>!1)}=void 0===n?{}:n;const i=Array.from(e.children),u=Array.from(t.children),a=(l=i,u.reduce((e,t,n)=>(l.some(e=>s(t,e))||e.push({el:t,index:n}),e),[]));var l;const h=function(e,t){return e.reduce((e,n)=>(t.some(e=>s(n,e))||e.push({el:n}),e),[])}(i,u);return h.reverse().filter(e=>{let{el:t}=e;return r(t)}).filter(e=>{let{el:t}=e;return!o(t)}).forEach(t=>{let{el:n}=t;return e.removeChild(n)}),a.filter(e=>{let{el:t}=e;return r(t)}).forEach(t=>{let{el:n,index:r=0}=t;e.insertBefore(n,e.children[r+1]||null)}),{removed:h.map(e=>{let{el:t}=e;return t}),added:a.map(e=>{let{el:t}=e;return t})}}(document.head,e.head,{shouldPersist:e=>t.isPersistentTag(e)});t.swup.log(`Removed ${n.length} / added ${l.length} tags in head`);const h=(u=document.documentElement).lang!==(a=e.documentElement).lang?(u.lang=a.lang,u.lang):null;h&&t.swup.log(`Updated lang attribute: ${h}`);const c=function(){if(t.options.awaitAssets){const n=(void 0===(e=t.options.timeout)&&(e=0),l.filter(o).map(t=>function(e,t){void 0===t&&(t=0);const n=t=>{(e=>{let{href:t}=e;return Array.from(document.styleSheets).map(e=>{let{href:t}=e;return t}).includes(t)})(e)?t():setTimeout(()=>n(t),10)};return new Promise(e=>{n(e),t>0&&setTimeout(e,t)})}(t,e))),r=function(){if(n.length)return t.swup.log(`Waiting for ${n.length} assets to load`),Promise.resolve(Promise.all(n)).then(function(){})}();if(r&&r.then)return r.then(function(){})}var e}();return Promise.resolve(c&&c.then?c.then(function(){}):void 0)}catch(e){return Promise.reject(e)}var u,a},this.options={...this.defaults,...e},this.options.persistAssets&&!this.options.persistTags&&(this.options.persistTags="link[rel=stylesheet], script[src], style")}mount(){this.before("content:replace",this.updateHead)}isPersistentTag(e){const{persistTags:t}=this.options;return"function"==typeof t?t(e):"string"==typeof t?e.matches(t):Boolean(t)}}}); +//# sourceMappingURL=index.umd.js.map diff --git a/assets/ts/modules/swupMorphPlugin.js b/assets/ts/modules/swupMorphPlugin.js index d2fc01b9..c2517fc9 100644 --- a/assets/ts/modules/swupMorphPlugin.js +++ b/assets/ts/modules/swupMorphPlugin.js @@ -1,1165 +1,2 @@ -(function webpackUniversalModuleDefinition(root, factory) { - if(typeof exports === 'object' && typeof module === 'object') - module.exports = factory(); - else if(typeof define === 'function' && define.amd) - define([], factory); - else if(typeof exports === 'object') - exports["SwupMorphPlugin"] = factory(); - else - root["SwupMorphPlugin"] = factory(); -})(window, function() { -return /******/ (function(modules) { // webpackBootstrap -/******/ // The module cache -/******/ var installedModules = {}; -/******/ -/******/ // The require function -/******/ function __webpack_require__(moduleId) { -/******/ -/******/ // Check if module is in cache -/******/ if(installedModules[moduleId]) { -/******/ return installedModules[moduleId].exports; -/******/ } -/******/ // Create a new module (and put it into the cache) -/******/ var module = installedModules[moduleId] = { -/******/ i: moduleId, -/******/ l: false, -/******/ exports: {} -/******/ }; -/******/ -/******/ // Execute the module function -/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__); -/******/ -/******/ // Flag the module as loaded -/******/ module.l = true; -/******/ -/******/ // Return the exports of the module -/******/ return module.exports; -/******/ } -/******/ -/******/ -/******/ // expose the modules object (__webpack_modules__) -/******/ __webpack_require__.m = modules; -/******/ -/******/ // expose the module cache -/******/ __webpack_require__.c = installedModules; -/******/ -/******/ // define getter function for harmony exports -/******/ __webpack_require__.d = function(exports, name, getter) { -/******/ if(!__webpack_require__.o(exports, name)) { -/******/ Object.defineProperty(exports, name, { enumerable: true, get: getter }); -/******/ } -/******/ }; -/******/ -/******/ // define __esModule on exports -/******/ __webpack_require__.r = function(exports) { -/******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { -/******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); -/******/ } -/******/ Object.defineProperty(exports, '__esModule', { value: true }); -/******/ }; -/******/ -/******/ // create a fake namespace object -/******/ // mode & 1: value is a module id, require it -/******/ // mode & 2: merge all properties of value into the ns -/******/ // mode & 4: return value when already ns object -/******/ // mode & 8|1: behave like require -/******/ __webpack_require__.t = function(value, mode) { -/******/ if(mode & 1) value = __webpack_require__(value); -/******/ if(mode & 8) return value; -/******/ if((mode & 4) && typeof value === 'object' && value && value.__esModule) return value; -/******/ var ns = Object.create(null); -/******/ __webpack_require__.r(ns); -/******/ Object.defineProperty(ns, 'default', { enumerable: true, value: value }); -/******/ if(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key)); -/******/ return ns; -/******/ }; -/******/ -/******/ // getDefaultExport function for compatibility with non-harmony modules -/******/ __webpack_require__.n = function(module) { -/******/ var getter = module && module.__esModule ? -/******/ function getDefault() { return module['default']; } : -/******/ function getModuleExports() { return module; }; -/******/ __webpack_require__.d(getter, 'a', getter); -/******/ return getter; -/******/ }; -/******/ -/******/ // Object.prototype.hasOwnProperty.call -/******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); }; -/******/ -/******/ // __webpack_public_path__ -/******/ __webpack_require__.p = ""; -/******/ -/******/ -/******/ // Load entry module and return exports -/******/ return __webpack_require__(__webpack_require__.s = 0); -/******/ }) -/************************************************************************/ -/******/ ([ -/* 0 */ -/***/ (function(module, exports, __webpack_require__) { - -"use strict"; - - -var _index = __webpack_require__(1); - -var _index2 = _interopRequireDefault(_index); - -function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } - -module.exports = _index2.default; // this is here for webpack to expose SwupPlugin as window.SwupPlugin - -/***/ }), -/* 1 */ -/***/ (function(module, exports, __webpack_require__) { - -"use strict"; - - -Object.defineProperty(exports, "__esModule", { - value: true -}); - -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; }; - -var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); - -var _plugin = __webpack_require__(2); - -var _plugin2 = _interopRequireDefault(_plugin); - -var _morph = __webpack_require__(3); - -var _morph2 = _interopRequireDefault(_morph); - -function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } - -function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } - -function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; } - -function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } - -var SwupMorphPlugin = function (_Plugin) { - _inherits(SwupMorphPlugin, _Plugin); - - function SwupMorphPlugin(options) { - _classCallCheck(this, SwupMorphPlugin); - - var _this = _possibleConstructorReturn(this, (SwupMorphPlugin.__proto__ || Object.getPrototypeOf(SwupMorphPlugin)).call(this)); - - _this.name = 'SwupMorphPlugin'; - - var defaultOptions = { - containers: [], - updateCallbacks: [] - }; - - _this.options = _extends({}, defaultOptions, options); - - _this.contentReplacedHandler = _this.morphContainers.bind(_this); - return _this; - } - - _createClass(SwupMorphPlugin, [{ - key: 'mount', - value: function mount() { - this.validateContainers(); - this.swup.on('contentReplaced', this.contentReplacedHandler); - } - }, { - key: 'unmount', - value: function unmount() { - this.swup.off('contentReplaced', this.contentReplacedHandler); - } - }, { - key: 'validateContainers', - value: function validateContainers() { - var _this2 = this; - - this.swup.options.containers.forEach(function (entry) { - if (_this2.options.containers.includes(entry)) { - throw new Error('[swup-morph-plugin] Please remove \'' + entry + '\' from the swup main options to let morph plugin take over.'); - } - }); - } - }, { - key: 'getContainers', - value: function getContainers() { - var doc = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : document; - - return this.options.containers.map(function (selector) { - var element = doc.querySelector(selector); - return { element: element, selector: selector }; - }); - } - }, { - key: 'getNewContainers', - value: function getNewContainers() { - var newDocument = this.getNewDocument(); - return this.getContainers(newDocument); - } - }, { - key: 'getNewDocument', - value: function getNewDocument() { - var pageContent = this.swup.cache.getCurrentPage().originalContent; - var newDocument = document.createElement('div'); - newDocument.innerHTML = pageContent; - return newDocument; - } - }, { - key: 'morphContainers', - value: function morphContainers() { - var containers = this.getContainers(); - var newContainers = this.getNewContainers(); - var callbacks = this.options.updateCallbacks || []; - - containers.forEach(function (_ref, index) { - var element = _ref.element; - var newElement = newContainers[index].element; - - if (element && newElement) { - (0, _morph2.default)(element, newElement, callbacks); - } - }); - } - }]); - - return SwupMorphPlugin; -}(_plugin2.default); - -exports.default = SwupMorphPlugin; - -/***/ }), -/* 2 */ -/***/ (function(module, exports, __webpack_require__) { - -"use strict"; - - -Object.defineProperty(exports, "__esModule", { - value: true -}); - -var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); - -function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } - -var Plugin = function () { - function Plugin() { - _classCallCheck(this, Plugin); - - this.isSwupPlugin = true; - } - - _createClass(Plugin, [{ - key: "mount", - value: function mount() { - // this is mount method rewritten by class extending - // and is executed when swup is enabled with plugin - } - }, { - key: "unmount", - value: function unmount() { - // this is unmount method rewritten by class extending - // and is executed when swup with plugin is disabled - } - }, { - key: "_beforeMount", - value: function _beforeMount() { - // here for any future hidden auto init - } - }, { - key: "_afterUnmount", - value: function _afterUnmount() {} - // here for any future hidden auto-cleanup - - - // this is here so we can tell if plugin was created by extending this class - - }]); - - return Plugin; -}(); - -exports.default = Plugin; - -/***/ }), -/* 3 */ -/***/ (function(module, exports, __webpack_require__) { - -"use strict"; - - -Object.defineProperty(exports, "__esModule", { - value: true -}); -exports.shouldMorphCallbacks = exports.isTextInput = exports.isMutableElement = undefined; - -var _morphdom = __webpack_require__(4); - -var _morphdom2 = _interopRequireDefault(_morphdom); - -function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } - -function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } } - -/** - * Morph dom nodes using morphdom, adding helpers and callbacks - */ - -var inputTags = { - INPUT: true, - TEXTAREA: true, - SELECT: true -}; - -var mutableTags = { - INPUT: true, - TEXTAREA: true, - OPTION: true -}; - -var textInputTypes = { - 'datetime-local': true, - 'select-multiple': true, - 'select-one': true, - color: true, - date: true, - datetime: true, - email: true, - month: true, - number: true, - password: true, - range: true, - search: true, - tel: true, - text: true, - textarea: true, - time: true, - url: true, - week: true -}; - -var permanentAttributeName = 'data-morph-persist'; - -var isMutableElement = exports.isMutableElement = function isMutableElement(el) { - return mutableTags[el.tagName]; -}; - -var isTextInput = exports.isTextInput = function isTextInput(el) { - return inputTags[el.tagName] && textInputTypes[el.type]; -}; - -var verifyNotMutable = function verifyNotMutable(fromEl, toEl) { - // Skip nodes that are equal: - // https://github.com/patrick-steele-idem/morphdom#can-i-make-morphdom-blaze-through-the-dom-tree-even-faster-yes - if (!isMutableElement(fromEl) && fromEl.isEqualNode(toEl)) return false; - return true; -}; - -var verifyNotPermanent = function verifyNotPermanent(fromEl, toEl) { - var permanent = fromEl.closest('[' + permanentAttributeName + ']'); - - // only morph attributes on the active non-permanent text input - if (!permanent && isTextInput(fromEl) && fromEl === document.activeElement) { - var ignore = { value: true }; - Array.from(toEl.attributes).forEach(function (attribute) { - if (!ignore[attribute.name]) fromEl.setAttribute(attribute.name, attribute.value); - }); - return false; - } - - return !permanent; -}; - -var shouldMorphCallbacks = exports.shouldMorphCallbacks = [verifyNotMutable, verifyNotPermanent]; - -var shouldMorph = function shouldMorph(fromEl, toEl) { - var callbacks = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : []; - - var callbackResults = callbacks.map(function (callback) { - return typeof callback === 'function' ? callback(fromEl, toEl) : true; - }); - return !callbackResults.includes(false); -}; - -var morph = function morph(from, to) { - var updateCallbacks = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : []; - - var callbacks = [].concat(shouldMorphCallbacks, _toConsumableArray(updateCallbacks)); - (0, _morphdom2.default)(from, to, { - onBeforeElUpdated: function onBeforeElUpdated(fromEl, toEl) { - return shouldMorph(fromEl, toEl, callbacks); - } - }); -}; - -exports.default = morph; - -/***/ }), -/* 4 */ -/***/ (function(module, __webpack_exports__, __webpack_require__) { - -"use strict"; -__webpack_require__.r(__webpack_exports__); -var DOCUMENT_FRAGMENT_NODE = 11; - -function morphAttrs(fromNode, toNode) { - var toNodeAttrs = toNode.attributes; - var attr; - var attrName; - var attrNamespaceURI; - var attrValue; - var fromValue; - - // document-fragments dont have attributes so lets not do anything - if (toNode.nodeType === DOCUMENT_FRAGMENT_NODE || fromNode.nodeType === DOCUMENT_FRAGMENT_NODE) { - return; - } - - // update attributes on original DOM element - for (var i = toNodeAttrs.length - 1; i >= 0; i--) { - attr = toNodeAttrs[i]; - attrName = attr.name; - attrNamespaceURI = attr.namespaceURI; - attrValue = attr.value; - - if (attrNamespaceURI) { - attrName = attr.localName || attrName; - fromValue = fromNode.getAttributeNS(attrNamespaceURI, attrName); - - if (fromValue !== attrValue) { - if (attr.prefix === 'xmlns'){ - attrName = attr.name; // It's not allowed to set an attribute with the XMLNS namespace without specifying the `xmlns` prefix - } - fromNode.setAttributeNS(attrNamespaceURI, attrName, attrValue); - } - } else { - fromValue = fromNode.getAttribute(attrName); - - if (fromValue !== attrValue) { - fromNode.setAttribute(attrName, attrValue); - } - } - } - - // Remove any extra attributes found on the original DOM element that - // weren't found on the target element. - var fromNodeAttrs = fromNode.attributes; - - for (var d = fromNodeAttrs.length - 1; d >= 0; d--) { - attr = fromNodeAttrs[d]; - attrName = attr.name; - attrNamespaceURI = attr.namespaceURI; - - if (attrNamespaceURI) { - attrName = attr.localName || attrName; - - if (!toNode.hasAttributeNS(attrNamespaceURI, attrName)) { - fromNode.removeAttributeNS(attrNamespaceURI, attrName); - } - } else { - if (!toNode.hasAttribute(attrName)) { - fromNode.removeAttribute(attrName); - } - } - } -} - -var range; // Create a range object for efficently rendering strings to elements. -var NS_XHTML = 'http://www.w3.org/1999/xhtml'; - -var doc = typeof document === 'undefined' ? undefined : document; -var HAS_TEMPLATE_SUPPORT = !!doc && 'content' in doc.createElement('template'); -var HAS_RANGE_SUPPORT = !!doc && doc.createRange && 'createContextualFragment' in doc.createRange(); - -function createFragmentFromTemplate(str) { - var template = doc.createElement('template'); - template.innerHTML = str; - return template.content.childNodes[0]; -} - -function createFragmentFromRange(str) { - if (!range) { - range = doc.createRange(); - range.selectNode(doc.body); - } - - var fragment = range.createContextualFragment(str); - return fragment.childNodes[0]; -} - -function createFragmentFromWrap(str) { - var fragment = doc.createElement('body'); - fragment.innerHTML = str; - return fragment.childNodes[0]; -} - -/** - * This is about the same - * var html = new DOMParser().parseFromString(str, 'text/html'); - * return html.body.firstChild; - * - * @method toElement - * @param {String} str - */ -function toElement(str) { - str = str.trim(); - if (HAS_TEMPLATE_SUPPORT) { - // avoid restrictions on content for things like `Hi` which - // createContextualFragment doesn't support - //